summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-10-01 22:38:21 +0200
committerChristian Grothoff <christian@grothoff.org>2021-10-01 22:38:21 +0200
commit0e60574acfb81d6bc279aac469e023e5c689a21d (patch)
tree32f7e2aabba2bdfcf3d113c2ca3430d9d21d3747
parentc291d70a2e05409738ae30db468438fffc4e63e2 (diff)
downloadanastasis-0e60574acfb81d6bc279aac469e023e5c689a21d.tar.gz
anastasis-0e60574acfb81d6bc279aac469e023e5c689a21d.tar.bz2
anastasis-0e60574acfb81d6bc279aac469e023e5c689a21d.zip
let there be Spain
-rw-r--r--contrib/Makefile.am1
-rw-r--r--contrib/pp/.gitignore3
-rw-r--r--contrib/redux.countries.json11
-rw-r--r--contrib/redux.es.json50
-rw-r--r--contrib/tos/.gitignore3
-rw-r--r--src/reducer/Makefile.am1
-rw-r--r--src/reducer/validation_ES_DNI.c147
7 files changed, 197 insertions, 19 deletions
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index a360ab5..a2bdf27 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -55,6 +55,7 @@ pkgdata_DATA = \
redux.cz.json \
redux.de.json \
redux.dk.json \
+ redux.es.json \
redux.in.json \
redux.it.json \
redux.jp.json \
diff --git a/contrib/pp/.gitignore b/contrib/pp/.gitignore
new file mode 100644
index 0000000..fb83616
--- /dev/null
+++ b/contrib/pp/.gitignore
@@ -0,0 +1,3 @@
+sphinx.err
+sphinx.log
+_build/
diff --git a/contrib/redux.countries.json b/contrib/redux.countries.json
index aaaf134..8fb2e99 100644
--- a/contrib/redux.countries.json
+++ b/contrib/redux.countries.json
@@ -73,6 +73,17 @@
"call_code" : "+45"
},
{
+ "code" : "es",
+ "name" : "Spain",
+ "continent" : "Europe",
+ "continent_i18n" : { "es_ES" : "Europa" },
+ "name_i18n" : {
+ "es_ES": "España"
+ },
+ "currency": "EUR",
+ "call_code" : "+44"
+ },
+ {
"code" : "in",
"name" : "India",
"continent" : "India",
diff --git a/contrib/redux.es.json b/contrib/redux.es.json
new file mode 100644
index 0000000..5926b6d
--- /dev/null
+++ b/contrib/redux.es.json
@@ -0,0 +1,50 @@
+{
+ "license": "GPLv3+",
+ "SPDX-License-Identifier": "GPL3.0-or-later",
+ "required_attributes": [
+ {
+ "type": "string",
+ "name": "full_name",
+ "label": "Full name",
+ "widget": "anastasis_gtk_ia_full_name",
+ "uuid" : "9e8f463f-575f-42cb-85f3-759559997331"
+ },
+ {
+ "type": "date",
+ "name": "birthdate",
+ "label": "Birthdate",
+ "widget": "anastasis_gtk_ia_birthdate",
+ "uuid" : "83d655c7-bdb6-484d-904e-80c1058c8854"
+ },
+ {
+ "type": "string",
+ "name": "birthplace",
+ "label": "Birthplace",
+ "widget": "anastasis_gtk_ia_birthplace",
+ "uuid" : "4c822e8e-89c6-11eb-95c4-8b077ad8489f"
+ },
+ {
+ "type": "string",
+ "name": "tax_number",
+ "label": "Tax number",
+ "label_i18n":{
+ "es_ES":"Número de Identificación Fiscal (DNI, NIE)",
+ },
+ "widget": "anastasis_gtk_ia_es_dni",
+ "uuid" : "ac8bd865-6be8-445c-b650-6a18eef16a49",
+ "validation-regex": "^[0-9MXYZ][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$",
+ "validation-logic": "ES_DNI_check"
+ },
+ {
+ "type": "string",
+ "name": "ssn_number",
+ "label": "Social security number",
+ "label_i18n":{
+ "es_ES":"Número de Seguridad Social",
+ },
+ "widget": "anastasis_gtk_ia_es_ssn",
+ "uuid" : "22396a19-f3bb-497e-b63a-961fd639140e",
+ "validation-regex": "^[0-9]{11}$"
+ }
+ ]
+}
diff --git a/contrib/tos/.gitignore b/contrib/tos/.gitignore
new file mode 100644
index 0000000..fb83616
--- /dev/null
+++ b/contrib/tos/.gitignore
@@ -0,0 +1,3 @@
+sphinx.err
+sphinx.log
+_build/
diff --git a/src/reducer/Makefile.am b/src/reducer/Makefile.am
index 5cbe6f7..3b7edb6 100644
--- a/src/reducer/Makefile.am
+++ b/src/reducer/Makefile.am
@@ -22,6 +22,7 @@ libanastasisredux_la_SOURCES = \
validation_CZ_BN.c \
validation_DE_SVN.c \
validation_DE_TIN.c \
+ validation_ES_DNI.c \
validation_IN_AADHAR.c \
validation_IT_CF.c \
validation_XX_SQUARE.c \
diff --git a/src/reducer/validation_ES_DNI.c b/src/reducer/validation_ES_DNI.c
index 06bf143..6679f45 100644
--- a/src/reducer/validation_ES_DNI.c
+++ b/src/reducer/validation_ES_DNI.c
@@ -17,9 +17,75 @@
* @file reducer/validation_ES_DNI.c
* @brief validation logic for Spanish Documento Nacional de Identidad numbers, and Número de Identificación de Extranjeros
* @author Christian Grothoff
+ *
+ * Examples:
+ * 12345678Z, 39740191D, 14741806W, X8095495R
*/
#include <string.h>
#include <stdbool.h>
+#include <stdio.h>
+
+/**
+ * Function to validate a Spanish CIF number.
+ *
+ * @param civ number to validate
+ * @return true if validation passed, else false
+ */
+static bool
+validate_cif (const char *cif)
+{
+ size_t slen = strlen (cif);
+ char letter = cif[0];
+ const char *number = &cif[1];
+ char control = cif[slen - 1];
+ unsigned int sum = 0;
+
+ if (9 != slen)
+ return false;
+
+ for (unsigned int i = 0; i < slen - 2; i++)
+ {
+ unsigned int n = number[i] - '0';
+
+ if (n >= 10)
+ return false;
+ if (0 == (i % 2))
+ {
+ n *= 2;
+ sum += n < 10 ? n : n - 9;
+ }
+ else
+ {
+ sum += n;
+ }
+ }
+ sum %= 10;
+ if (0 != sum)
+ sum = 10 - sum;
+ {
+ char control_digit = "0123456789"[sum];
+ char control_letter = "JABCDEFGHI"[sum];
+
+ switch (letter)
+ {
+ case 'A':
+ case 'B':
+ case 'E':
+ case 'H':
+ return control == control_digit;
+ case 'N':
+ case 'P':
+ case 'Q':
+ case 'R':
+ case 'S':
+ case 'W':
+ return control == control_letter;
+ default:
+ return (control == control_letter) ||
+ (control == control_digit);
+ }
+ }
+}
/**
@@ -43,32 +109,75 @@ ES_DNI_check (const char *dni_number)
return false;
switch (dni_number[0])
{
+ case 'A':
+ case 'B':
+ case 'C':
+ case 'D':
+ case 'E':
+ case 'F':
+ case 'G':
+ case 'H':
+ case 'I':
+ case 'J':
+ case 'K':
+ case 'L':
+ case 'N':
+ case 'O':
+ case 'P':
+ case 'Q':
+ case 'R':
+ case 'S':
+ case 'T':
+ case 'U':
+ case 'V':
+ case 'W':
+ /* CIF: [A-W]\d{7}[0-9A-J] */
+ /* CIF is for companies, we only take those
+ of individuals here! */
+ return false; /* CIV is not allowed! */
+ case 'M':
+ /* special NIE, with CIF validation (?),
+ but for individuals, see
+ https://www.strongabogados.com/tax-id-spain.php */
+ return validate_cif (dni_number);
case 'X':
- fact = 0;
- dni_number++;
- break;
case 'Y':
- fact = 10000000;
- dni_number++;
- break;
case 'Z':
- fact = 20000000;
- dni_number++;
+ /* NIE */
+ fact = dni_number[0] - 'X';
+ /* 7 or 8 digits */
+ if (2 == sscanf (&dni_number[1],
+ "%8u%c%c",
+ &num,
+ &chksum,
+ &dummy))
+ {
+ num += fact * 100000000;
+ }
+ else if (2 == sscanf (&dni_number[1],
+ "%7u%c%c",
+ &num,
+ &chksum,
+ &dummy))
+ {
+ num += fact * 10000000;
+ }
+ else
+ {
+ return false;
+ }
break;
default:
fact = 0;
- /* domestic */
+ /* DNI */
+ if (2 != sscanf (dni_number,
+ "%8u%c%c",
+ &num,
+ &chksum,
+ &dummy))
+ return false;
+ break;
}
-
- if (2 != sscanf (dni_number,
- "%7u%c%c"
- & num,
- &chksum,
- &dummy))
- return false;
- num += fact;
- if (map[num % 23] != chksum)
- return false;
if (map[num % 23] != chksum)
return false;
return true;