summaryrefslogtreecommitdiff
path: root/src/reducer
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-02-27 16:22:13 +0100
committerChristian Grothoff <christian@grothoff.org>2022-02-27 16:22:13 +0100
commit9cc967321656dd8d50231047c7366c82a9897e9c (patch)
tree80d935eb801dc0fced7dcb9ded144d19a6cb71cd /src/reducer
parent18d7ebb1b74e81c5ccf750dda4cfe5c0c268f88d (diff)
downloadanastasis-9cc967321656dd8d50231047c7366c82a9897e9c.tar.gz
anastasis-9cc967321656dd8d50231047c7366c82a9897e9c.tar.bz2
anastasis-9cc967321656dd8d50231047c7366c82a9897e9c.zip
add support for INSEE numbers
Diffstat (limited to 'src/reducer')
-rw-r--r--src/reducer/Makefile.am1
-rw-r--r--src/reducer/validation_FR_INSEE.c66
2 files changed, 67 insertions, 0 deletions
diff --git a/src/reducer/Makefile.am b/src/reducer/Makefile.am
index bfdb521..6dad659 100644
--- a/src/reducer/Makefile.am
+++ b/src/reducer/Makefile.am
@@ -24,6 +24,7 @@ libanastasisredux_la_SOURCES = \
validation_DE_SVN.c \
validation_DE_TIN.c \
validation_ES_DNI.c \
+ validation_FR_INSEE.c \
validation_IN_AADHAR.c \
validation_IT_CF.c \
validation_NL_BSN.c \
diff --git a/src/reducer/validation_FR_INSEE.c b/src/reducer/validation_FR_INSEE.c
new file mode 100644
index 0000000..19d81fd
--- /dev/null
+++ b/src/reducer/validation_FR_INSEE.c
@@ -0,0 +1,66 @@
+/*
+ This file is part of Anastasis
+ Copyright (C) 2022 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_FR_INSEE.c
+ * @brief Validation for French INSEE Numbers
+ * @author Christian Grothoff
+ */
+#include <string.h>
+#include <stdbool.h>
+#include <stdio.h>
+
+
+/**
+ * Function to validate a French INSEE number.
+ *
+ * See https://en.wikipedia.org/wiki/INSEE_code
+ *
+ * Note that we do not implement checks on the month
+ * and also allow non-binary prefixes.
+ *
+ * @param insee_number social security number to validate (input)
+ * @return true if validation passed, else false
+ */
+bool
+FR_INSEE_check (const char *insee_number)
+{
+ char pfx[14];
+ unsigned long long num;
+ unsigned int cc;
+ char dum;
+
+ if (strlen (insee_number) != 15)
+ return false;
+ memcpy (pfx,
+ insee_number,
+ 13);
+ pfx[13] = '\0';
+ if (1 !=
+ sscanf (pfx,
+ "%llu%c",
+ &num,
+ &dum))
+ return false;
+ if (1 !=
+ sscanf (&insee_number[13],
+ "%u%c",
+ &cc,
+ &dum))
+ return false;
+ if (97 - cc != num % 97)
+ return false;
+ return true;
+}