[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 02/03: ahv number validation function
From: |
gnunet |
Subject: |
[taler-anastasis] 02/03: ahv number validation function |
Date: |
Mon, 02 Nov 2020 11:44:31 +0100 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
commit f4986cd16d66b3e807479f9a0e3d2678036d9c20
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Sun Nov 1 19:21:21 2020 +0100
ahv number validation function
---
contrib/redux.ch.json | 19 +++++++-------
src/lib/anastasis_api_redux.c | 59 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 10 deletions(-)
diff --git a/contrib/redux.ch.json b/contrib/redux.ch.json
index e434037..677b800 100644
--- a/contrib/redux.ch.json
+++ b/contrib/redux.ch.json
@@ -3,8 +3,8 @@
{
"type": "string",
"name": "full_name",
- "label": "Full name",
- "label_i18n":{
+ "label": "Full name",
+ "label_i18n":{
"de_DE":"Vollstaendiger Name",
"de_CH":"Vollstaendiger Name"
},
@@ -13,21 +13,20 @@
{
"type": "date",
"name": "birthdate",
- "label": "Birthdate",
+ "label": "Birthdate",
"label_i18n":{"de_CH":"Geburtsdatum"},
"widget": "anastasis_gtk_ia_birthdate"
},
{
- "type": "string",
- "name": "ahv_number",
- "label": "AHV number",
- "label_i18n":{
+ "type": "string",
+ "name": "ahv_number",
+ "label": "AHV number",
+ "label_i18n":{
"de_DE":"AHV-Nummer",
"de_CH":"AHV-Nummer"
},
- "widget": "anastasis_gtk_ia_ahv"
+ "widget": "anastasis_gtk_ia_ahv",
+ "validation": "/(756.\d{4}.\d{4}.\d{2}|756\d{10})/g"
}
]
}
-
-
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index b362a3c..8091a58 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -408,6 +408,65 @@ ANASTASIS_redux_countries_init_ (void)
}
+/**
+ * Function to validate an AHV number.
+ * @param ahv_number ahv number to validate
+ * @return true if validation passed, else false
+ */
+static bool
+validate_ahv (const char*ahv_number)
+{
+ unsigned int checknum;
+ char num_to_check[12];
+
+ // check if ahv contains points
+ if (strstr (ahv_number, "."))
+ {
+ for (unsigned int i = 0; i < 3; i++)
+ {
+ num_to_check[i] = ahv_number[i];
+ }
+ for (unsigned int i = 0; i < 4; i++)
+ {
+ num_to_check[3 + i] = ahv_number[4 + i];
+ }
+ for (unsigned int i = 0; i < 4; i++)
+ {
+ num_to_check[7 + i] = ahv_number[9 + i];
+ }
+ num_to_check[11] = ahv_number[15];
+ }
+ else
+ {
+ for (unsigned int i = 0; i < 12; i++)
+ {
+ num_to_check[i] = ahv_number[i];
+ }
+ }
+ int calculation = 0;
+ int next_ten = 0;
+ checknum = (int) ahv_number[strlen (ahv_number) - 1] - 48;
+
+ for (unsigned int i = 0; i < strlen (num_to_check); i++)
+ {
+ int x = (int) num_to_check[strlen (num_to_check) - i - 1] - 48;
+ if (0 == i % 2)
+ calculation = calculation + (x * 3);
+ else
+ calculation = calculation + x;
+ }
+ // round up to the next ten
+ next_ten = (calculation + 10) / 10;
+ next_ten = next_ten * 10;
+ // calculate check number
+ calculation = next_ten - calculation;
+
+ if (checknum == calculation)
+ return true;
+ return false;
+}
+
+
/**
* Function to load json containing country specific
* identity attributes. Returns #GNUNET_OK if operation
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.