Used to validate that an AI component conforms to the format required for an IBAN.
68{
69
71 size_t pos;
72 unsigned int csum = 0;
73 unsigned char weight;
74
75
76
77
78
79 static const unsigned char iban_weights[256] = {
80 ['0'] = 1, ['1'] = 2, ['2'] = 3, ['3'] = 4, ['4'] = 5,
81 ['5'] = 6, ['6'] = 7, ['7'] = 8, ['8'] = 9, ['9'] = 10,
82 ['A'] = 11, ['B'] = 12, ['C'] = 13, ['D'] = 14, ['E'] = 15,
83 ['F'] = 16, ['G'] = 17, ['H'] = 18, ['I'] = 19, ['J'] = 20,
84 ['K'] = 21, ['L'] = 22, ['M'] = 23, ['N'] = 24, ['O'] = 25,
85 ['P'] = 26, ['Q'] = 27, ['R'] = 28, ['S'] = 29, ['T'] = 30,
86 ['U'] = 31, ['V'] = 32, ['W'] = 33, ['X'] = 34, ['Y'] = 35, ['Z'] = 36
87 };
88
89 assert(data);
90
91
92
93
94
98 0,
99 data_len
100 );
101
102
103
104
105
111 0,
112 2
113 );
114
118 0,
119 data_len
120 );
121
125 0,
126 data_len
127 );
128
129
130 for (pos = 4; pos < data_len + 4; pos++) {
131 size_t actual_pos = (pos < data_len) ? pos : (pos - data_len);
132
133 weight = iban_weights[(unsigned char)data[actual_pos]];
137 actual_pos,
138 1
139 );
140
141 csum *= weight <= 10 ? 10 : 100;
142 csum += weight - 1;
143 csum %= 97;
144 }
145
149 2,
150 2
151 );
152
154
155}
#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:76
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:42
#define IBAN_MIN_LENGTH
No clear minimum length; sufficient for check characters.
Definition lint_iban.c:39