[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: draft DNI validation logic
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: draft DNI validation logic |
Date: |
Fri, 01 Oct 2021 18:38:01 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new c291d70 draft DNI validation logic
c291d70 is described below
commit c291d70a2e05409738ae30db468438fffc4e63e2
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Thu Sep 30 15:00:58 2021 +0200
draft DNI validation logic
---
src/reducer/validation_ES_DNI.c | 75 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/src/reducer/validation_ES_DNI.c b/src/reducer/validation_ES_DNI.c
new file mode 100644
index 0000000..06bf143
--- /dev/null
+++ b/src/reducer/validation_ES_DNI.c
@@ -0,0 +1,75 @@
+/*
+ This file is part of Anastasis
+ Copyright (C) 2021 Anastasis SARL
+
+ Anastasis is free software; you can redistribute it and/or modify it under
the
+ terms of the GNU Lesser 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 Affero General Public License for more
details.
+
+ You should have received a copy of the GNU Affero General Public License
along with
+ Anastasis; see the file COPYING.GPL. If not, see
<http://www.gnu.org/licenses/>
+*/
+/**
+ * @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
+ */
+#include <string.h>
+#include <stdbool.h>
+
+
+/**
+ * Function to validate a Spanish DNI number.
+ *
+ * See https://www.ordenacionjuego.es/en/calculo-digito-control
+ *
+ * @param dni_number number to validate (input)
+ * @return true if validation passed, else false
+ */
+bool
+ES_DNI_check (const char *dni_number)
+{
+ const char map[] = "TRWAGMYFPDXBNJZSQVHLCKE";
+ unsigned int num;
+ char chksum;
+ unsigned int fact;
+ char dummy;
+
+ if (strlen (dni_number) < 8)
+ return false;
+ switch (dni_number[0])
+ {
+ case 'X':
+ fact = 0;
+ dni_number++;
+ break;
+ case 'Y':
+ fact = 10000000;
+ dni_number++;
+ break;
+ case 'Z':
+ fact = 20000000;
+ dni_number++;
+ break;
+ default:
+ fact = 0;
+ /* domestic */
+ }
+
+ 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;
+}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: draft DNI validation logic,
gnunet <=