summaryrefslogtreecommitdiff
path: root/src/reducer
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-02-27 15:57:07 +0100
committerChristian Grothoff <christian@grothoff.org>2022-02-27 15:57:07 +0100
commit18d7ebb1b74e81c5ccf750dda4cfe5c0c268f88d (patch)
tree90ffe7941bf0fc5d3d3c0d490b883e0d8a604630 /src/reducer
parentd79df04ba7ea596c308d8d0803d6b5948d7e1252 (diff)
downloadanastasis-18d7ebb1b74e81c5ccf750dda4cfe5c0c268f88d.tar.gz
anastasis-18d7ebb1b74e81c5ccf750dda4cfe5c0c268f88d.tar.bz2
anastasis-18d7ebb1b74e81c5ccf750dda4cfe5c0c268f88d.zip
add support for NL
Diffstat (limited to 'src/reducer')
-rw-r--r--src/reducer/Makefile.am1
-rw-r--r--src/reducer/validation_NL_BSN.c57
2 files changed, 58 insertions, 0 deletions
diff --git a/src/reducer/Makefile.am b/src/reducer/Makefile.am
index 7aa389e..bfdb521 100644
--- a/src/reducer/Makefile.am
+++ b/src/reducer/Makefile.am
@@ -26,6 +26,7 @@ libanastasisredux_la_SOURCES = \
validation_ES_DNI.c \
validation_IN_AADHAR.c \
validation_IT_CF.c \
+ validation_NL_BSN.c \
validation_XX_SQUARE.c \
validation_XY_PRIME.c
libanastasisredux_la_LIBADD = \
diff --git a/src/reducer/validation_NL_BSN.c b/src/reducer/validation_NL_BSN.c
new file mode 100644
index 0000000..f92bb38
--- /dev/null
+++ b/src/reducer/validation_NL_BSN.c
@@ -0,0 +1,57 @@
+/*
+ This file is part of Anastasis
+ Copyright (C) 2020, 2021 Anastasis SARL
+
+ Anastasis is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ Anastasis; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file reducer/validation_NL_BSN.c
+ * @brief Validation for Dutch Buergerservicenummern
+ * @author Christian Grothoff
+ */
+#include <string.h>
+#include <stdbool.h>
+
+
+/**
+ * Function to validate a Dutch Social Security number.
+ *
+ * See https://nl.wikipedia.org/wiki/Burgerservicenummer
+ *
+ * @param bsn_number social security number to validate (input)
+ * @return true if validation passed, else false
+ */
+bool
+NL_BSN_check (const char *bsn_number)
+{
+ static const int factors[] = {
+ 9, 8, 7, 6, 5, 4, 3, 2, -1
+ };
+ unsigned int sum = 0;
+
+ if (strlen (bsn_number) != 9)
+ return false;
+ for (unsigned int i = 0; i<8; i++)
+ {
+ unsigned char c = (unsigned char) bsn_number[i];
+
+ if ( ('0' > c) || ('9' < c) )
+ return false;
+ sum += (c - '0') * factors[i];
+ }
+ {
+ unsigned char c = (unsigned char) bsn_number[8];
+ unsigned int v = (c - '0');
+
+ return (sum % 11 == v);
+ }
+}