Used to validate that an AI component conforms to the format required for an IBAN.
67{
68
70 size_t pos;
71 unsigned int csum = 0;
72
73
74
75
76
77 static const unsigned char iban_weights[256] = {
78 ['0'] = 1, ['1'] = 2, ['2'] = 3, ['3'] = 4, ['4'] = 5,
79 ['5'] = 6, ['6'] = 7, ['7'] = 8, ['8'] = 9, ['9'] = 10,
80 ['A'] = 11, ['B'] = 12, ['C'] = 13, ['D'] = 14, ['E'] = 15,
81 ['F'] = 16, ['G'] = 17, ['H'] = 18, ['I'] = 19, ['J'] = 20,
82 ['K'] = 21, ['L'] = 22, ['M'] = 23, ['N'] = 24, ['O'] = 25,
83 ['P'] = 26, ['Q'] = 27, ['R'] = 28, ['S'] = 29, ['T'] = 30,
84 ['U'] = 31, ['V'] = 32, ['W'] = 33, ['X'] = 34, ['Y'] = 35, ['Z'] = 36
85 };
86
87 assert(data);
88
89
90
91
92
96 0,
97 data_len
98 );
99
100
101
102
103
109 0,
110 2
111 );
112
116 0,
117 data_len
118 );
119
123 0,
124 data_len
125 );
126
127
128 for (pos = 4; pos < data_len + 4; pos++) {
129 size_t actual_pos = (pos < data_len) ? pos : (pos - data_len);
130 unsigned char weight = iban_weights[(unsigned char)data[actual_pos]];
131
135 actual_pos,
136 1
137 );
138
139 csum *= weight <= 10 ? 10 : 100;
140 csum += weight - 1;
141 csum %= 97;
142 }
143
147 2,
148 2
149 );
150
152
153}
#define GS1_LINTER_UNLIKELY(x)
Implementation may provide hint to the compiler that the expression is likely to be false.
Definition gs1syntaxdictionary-utils.h:76
#define GS1_LINTER_RETURN_ERROR(error, position, length)
Return from a linter indicating that a problem was detected with the given data.
Definition gs1syntaxdictionary-utils.h:103
#define GS1_LINTER_RETURN_OK
Return from a linter indicating that no problem was detected with the given data.
Definition gs1syntaxdictionary-utils.h:88
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_iso3166alpha2(const char *data, size_t data_len, size_t *err_pos, size_t *err_len)
Definition lint_iso3166alpha2.c:75
gs1_lint_err_t
Linter return codes other than GS1_LINTER_OK indicate an error condition.
Definition gs1syntaxdictionary.h:76
@ GS1_LINTER_INCORRECT_IBAN_CHECKSUM
The IBAN is invalid since the check characters are incorrect.
Definition gs1syntaxdictionary.h:104
@ GS1_LINTER_INVALID_IBAN_CHARACTER
The IBAN contains an invalid character.
Definition gs1syntaxdictionary.h:102
@ GS1_LINTER_ILLEGAL_IBAN_COUNTRY_CODE
The IBAN must start with a valid ISO 3166 two-character country code.
Definition gs1syntaxdictionary.h:103
@ GS1_LINTER_IBAN_TOO_SHORT
The IBAN is too short.
Definition gs1syntaxdictionary.h:101
@ GS1_LINTER_OK
No issues were detected by the linter.
Definition gs1syntaxdictionary.h:77
@ GS1_LINTER_NOT_ISO3166_ALPHA2
A valid ISO 3166 two-character country code is required.
Definition gs1syntaxdictionary.h:99
@ GS1_LINTER_IBAN_TOO_LONG
The IBAN is too long.
Definition gs1syntaxdictionary.h:200
#define IBAN_MAX_LENGTH
Per specification.
Definition lint_iban.c:41
#define IBAN_MIN_LENGTH
No clear minimum length; sufficient for check characters.
Definition lint_iban.c:38