GS1 Syntax Dictionary: Linter reference
A reference to the AI component linter routines referred to by the GS1 Syntax Dictionary.
Macros
lint_iban.c File Reference

Purpose

The iban linter ensures that the data conforms to the format required for an International Bank Account Number (IBAN) number.

Remarks
The format for an IBAN is specified by ISO 13616-1: Financial services - International bank account number (IBAN) - Part 1: Structure of the IBAN.

Macros

#define IBAN_MIN_LENGTH   10
 No clear minimum length; sufficient for check characters.
 

Functional Description

◆ gs1_lint_iban()

GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_iban ( const char *const  data,
size_t *const  err_pos,
size_t *const  err_len 
)

Used to validate that an AI component conforms to the format required for an IBAN.

Parameters
[in]dataPointer to the null-terminated data to be linted. Must not be NULL.
[out]err_posTo facilitate error highlighting, the start position of the bad data is written to this pointer, if not NULL.
[out]err_lenThe length of the bad data is written to this pointer, if not NULL.
Returns
GS1_LINTER_OK if okay.
GS1_LINTER_INCORRECT_IBAN_CHECKSUM if the IBAN checksum is incorrect for the data.
GS1_LINTER_IBAN_TOO_SHORT if the data is too short to be an IBAN.
GS1_LINTER_INVALID_IBAN_CHARACTER if the data contains a character that isn't permissible within an IBAN.
GS1_LINTER_ILLEGAL_IBAN_COUNTRY_CODE if the leading two characters are not a valid ISO 3166 alpha-2 country code.
64 {
65 
66  char cc[3] = {0};
67  gs1_lint_err_t ret;
68  size_t len, pos;
69  const char *p;
70  unsigned int csum;
71 
72  static const char* const csetiban = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
73 
74  assert(data);
75 
76  len = strlen(data);
77 
78  if (len <= IBAN_MIN_LENGTH) {
79  if (err_pos) *err_pos = 0;
80  if (err_len) *err_len = len;
82  }
83 
84  /*
85  * Any character outside of the set of valid IBAN characters is illegal.
86  *
87  */
88  if ((pos = strspn(data, csetiban)) != len) {
89  if (err_pos) *err_pos = pos;
90  if (err_len) *err_len = 1;
92  }
93 
94  /*
95  * The first two characters must be an ISO 3166 alpha-2 country code.
96  *
97  */
98  strncpy(cc, data, 2);
99  ret = gs1_lint_iso3166alpha2(cc, err_pos, err_len);
100  assert(ret == GS1_LINTER_OK || ret == GS1_LINTER_NOT_ISO3166_ALPHA2);
101 
102  if (ret == GS1_LINTER_NOT_ISO3166_ALPHA2) {
103  if (err_pos) *err_pos = 0;
104  if (err_len) *err_len = 2;
106  }
107 
108  /*
109  * Compute the IBAN checksum as the sum of digits, with characters
110  * converted to digits (A => 10; B => 11), starting with the forth
111  * character and wrapping at the end.
112  *
113  */
114  csum = 0;
115  p = data + 4;
116  do {
117 
118  if (*p < 'A')
119  csum = csum * 10 + (unsigned int)(*p - '0');
120  else
121  csum = csum * 100 + (unsigned int)(*p - 'A' + 10);
122  csum %= 97;
123 
124  /*
125  * Next character, wrapping at the end.
126  *
127  */
128  p++;
129  if (p == data + len)
130  p = data;
131 
132  } while (p != data + 4);
133 
134  /*
135  * Sum (mod 97) is 1 for correctly formatted IBANs.
136  *
137  */
138  if (csum != 1) {
139  if (err_pos) *err_pos = 2;
140  if (err_len) *err_len = 2;
142  }
143 
144  return GS1_LINTER_OK;
145 
146 }
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_iso3166alpha2(const char *data, 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:65
@ GS1_LINTER_INCORRECT_IBAN_CHECKSUM
The IBAN is invalid since the check characters are incorrect.
Definition: gs1syntaxdictionary.h:93
@ GS1_LINTER_INVALID_IBAN_CHARACTER
The IBAN contains an invalid character.
Definition: gs1syntaxdictionary.h:91
@ GS1_LINTER_ILLEGAL_IBAN_COUNTRY_CODE
The IBAN must start with a valid ISO 3166 two-character country code.
Definition: gs1syntaxdictionary.h:92
@ GS1_LINTER_IBAN_TOO_SHORT
The IBAN is too short.
Definition: gs1syntaxdictionary.h:90
@ GS1_LINTER_OK
No issues were detected by the linter.
Definition: gs1syntaxdictionary.h:66
@ GS1_LINTER_NOT_ISO3166_ALPHA2
A valid ISO 3166 two-character country code is required.
Definition: gs1syntaxdictionary.h:88
#define IBAN_MIN_LENGTH
No clear minimum length; sufficient for check characters.
Definition: lint_iban.c:38