gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-anastasis] branch master updated (ef84fa4 -> c4f3b09)


From: gnunet
Subject: [taler-anastasis] branch master updated (ef84fa4 -> c4f3b09)
Date: Mon, 05 Jul 2021 17:50:28 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a change to branch master
in repository anastasis.

    from ef84fa4  remove redundant birthdate q
     new 90b8a9d  add italian
     new eb52585  add it rules:
     new c4f3b09  add it rules

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 contrib/Makefile.am                      |   1 +
 contrib/redux.countries.json             |  11 ++
 contrib/{redux.cz.json => redux.it.json} |  16 +--
 src/reducer/Makefile.am                  |   1 +
 src/reducer/validation_IT_CF.c           | 198 +++++++++++++++++++++++++++++++
 5 files changed, 219 insertions(+), 8 deletions(-)
 copy contrib/{redux.cz.json => redux.it.json} (67%)
 create mode 100644 src/reducer/validation_IT_CF.c

diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index a78b9e8..4304bcf 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -21,6 +21,7 @@ pkgdata_DATA = \
   redux.de.json \
   redux.dk.json \
   redux.in.json \
+  redux.it.json \
   redux.jp.json \
   redux.sk.json \
   redux.us.json \
diff --git a/contrib/redux.countries.json b/contrib/redux.countries.json
index 88fded4..7902578 100644
--- a/contrib/redux.countries.json
+++ b/contrib/redux.countries.json
@@ -84,6 +84,17 @@
                "currency": "INR",
                "call_code" : "+91"
        },
+       {
+               "code" : "it",
+               "name" : "Italy",
+               "continent" : "Europe",
+               "name_i18n" : {
+                       "de_DE": "Italien",
+                       "en_UK": "Italy"
+               },
+               "currency": "EUR",
+               "call_code" : "+39"
+       },
        {
                "code" : "jp",
                "name" : "Japan",
diff --git a/contrib/redux.cz.json b/contrib/redux.it.json
similarity index 67%
copy from contrib/redux.cz.json
copy to contrib/redux.it.json
index d5967a1..e4d0945 100644
--- a/contrib/redux.cz.json
+++ b/contrib/redux.it.json
@@ -28,16 +28,16 @@
        },
        {
            "type": "string",
-           "name": "birth_number",
-           "label": "Birth Number",
+           "name": "fiscal_code",
+           "label": "Codice fiscale",
            "label_i18n":{
-               "en": "Birth Number",
-               "cz": "rodné číslo"
+               "it": "Codice fiscale",
+               "en": "Fiscal code"
            },
-           "widget": "anastasis_gtk_ia_birthnumber_cz",
-            "uuid": "03e3a05b-1192-44f1-ac36-7425512eee1a",
-           "validation-regex": 
"^[0-9]{2}(((0|2|5|7)[0-9])|10|11|31|32|51|52|81|82)/[0-9]{3}[0-9]?$",
-           "validation-logic": "CZ_BN_check"
+           "widget": "anastasis_gtk_ia_cf_it",
+            "uuid": "88f53c51-52ad-4d63-a163-ec042589f925",
+           "validation-regex": 
"^[[:upper:]]{6}[0-9]{2}[A-EHLMPRT](([0-24-6][0-9])|(30|31|70|71))[A-MZ][0-9]{3}[A-Z]$",
+           "validation-logic": "IT_CF_check"
        }
     ]
 }
diff --git a/src/reducer/Makefile.am b/src/reducer/Makefile.am
index d9d058f..5cbe6f7 100644
--- a/src/reducer/Makefile.am
+++ b/src/reducer/Makefile.am
@@ -23,6 +23,7 @@ libanastasisredux_la_SOURCES = \
   validation_DE_SVN.c \
   validation_DE_TIN.c \
   validation_IN_AADHAR.c \
+  validation_IT_CF.c \
   validation_XX_SQUARE.c \
   validation_XY_PRIME.c
 libanastasisredux_la_LIBADD = \
diff --git a/src/reducer/validation_IT_CF.c b/src/reducer/validation_IT_CF.c
new file mode 100644
index 0000000..ecdad90
--- /dev/null
+++ b/src/reducer/validation_IT_CF.c
@@ -0,0 +1,198 @@
+/*
+  This file is part of Anastasis
+  Copyright (C) 2021 Taler Systems SA
+
+  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 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 redux/validation_IT_CF.c
+ * @brief validation of Italian Code Fiscales
+ * @author Christian Grothoff
+ */
+#include <string.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <math.h>
+
+struct MapEntry
+{
+  char in;
+  unsigned int out;
+};
+
+
+static const struct MapEntry odd[] = {
+  { '0',  1},
+  { '9',  21},
+  { 'I',  19 },
+  { 'R',  8},
+  { '1',  0},
+  { 'A',  1},
+  { 'J',  21},
+  { 'S',  12},
+  {'2',   5},
+  {'B',   0},
+  {'K',   2},
+  {'T',   14},
+  {'3',   7},
+  {'C',   5},
+  {'L',   4},
+  {'U',   16},
+  {'4',   9},
+  {'D',   7},
+  {'M',   18},
+  {'V',   10},
+  {'5',   13},
+  {'E',   9},
+  {'N',   20},
+  {'W',   22},
+  {'6',   15},
+  {'F',   13},
+  {'O',   11},
+  {'X',   25},
+  {'7',   17},
+  {'G',   15},
+  {'P',   3},
+  {'Y',   24},
+  {'8',   19},
+  {'H',   17},
+  {'Q',   6},
+  {'Z',   23},
+  {'\0', 0}
+};
+
+
+static const struct MapEntry even[] = {
+  { '0',  0},
+  { '1',   1},
+  { '2',  2  },
+  { '3',  3},
+  { '4',  4},
+  { '5',  5},
+  { '6',  6 },
+  { '7',  7 },
+  {'8',   8},
+  {'9',   9},
+  {'A',   0},
+  {'B',   1},
+  {'C',   2},
+  {'D',   3},
+  {'E',   4},
+  {'F',   5},
+  {'G',   6},
+  {'H',   7},
+  {'I',   8},
+  {'J',   9},
+  {'K',   10},
+  {'L',   11},
+  {'M',   12},
+  {'N',   13},
+  {'O',   14},
+  {'P',   15},
+  {'Q',   16},
+  {'R',   17},
+  {'S',   18},
+  {'T',   19},
+  {'U',   20},
+  {'V',   21},
+  {'W',   22},
+  {'X',   23},
+  {'Y',   24},
+  {'Z',   25},
+  {'\0', 0}
+};
+
+
+static const struct MapEntry rem[] = {
+  {'A',   0},
+  {'B',   1},
+  {'C',   2},
+  {'D',   3},
+  {'E',   4},
+  {'F',   5},
+  {'G',   6},
+  {'H',   7},
+  {'I',   8},
+  {'J',   9},
+  {'K',   10},
+  {'L',   11},
+  {'M',   12},
+  {'N',   13},
+  {'O',   14},
+  {'P',   15},
+  {'Q',   16},
+  {'R',   17},
+  {'S',   18},
+  {'T',   19},
+  {'U',   20},
+  {'V',   21},
+  {'W',   22},
+  {'X',   23},
+  {'Y',   24},
+  {'Z',   25},
+  {'\0', 0}
+};
+
+
+/**
+ * Lookup @a in in @a map. Set @a fail to true if @a in is not found.
+ *
+ * @param map character map to search
+ * @param in character to search for
+ * @param[out] fail set to true on error
+ * @return map value, 0 on error
+ */
+static unsigned int
+lookup (const struct MapEntry *map,
+        char in,
+        bool *fail)
+{
+  for (unsigned int i = 0; '\0' != map[i].in; i++)
+    if (in == map[i].in)
+      return map[i].out;
+  *fail = true;
+  return 0;
+}
+
+
+/**
+ * Function to validate an italian code fiscale number.
+ * See https://en.wikipedia.org/wiki/Italian_fiscal_code
+ *
+ * @param cf_number square number to validate (input)
+ * @return true if @a cf_number is a valid, else false
+ */
+bool
+IT_CF_check (const char *cf_number)
+{
+  unsigned int sum = 0;
+  bool fail = false;
+
+  if (strlen (cf_number) != 16)
+    return false;
+  for (unsigned int i = 0; i<15; i += 2)
+    sum += lookup (odd,
+                   cf_number[i],
+                   &fail);
+  for (unsigned int i = 1; i<15; i += 2)
+    sum += lookup (even,
+                   cf_number[i],
+                   &fail);
+  sum %= 26;
+  if (sum != lookup (rem,
+                     cf_number[15],
+                     &fail))
+    return false;
+  if (fail)
+    return false;
+  return true;
+}

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]