aboutsummaryrefslogtreecommitdiff
path: root/src/reducer/validation_DE_TIN.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reducer/validation_DE_TIN.c')
-rw-r--r--src/reducer/validation_DE_TIN.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/reducer/validation_DE_TIN.c b/src/reducer/validation_DE_TIN.c
new file mode 100644
index 0000000..9c97365
--- /dev/null
+++ b/src/reducer/validation_DE_TIN.c
@@ -0,0 +1,57 @@
1/*
2 This file is part of Anastasis
3 Copyright (C) 2020, 2021 Taler Systems SA
4
5 Anastasis is free software; you can redistribute it and/or modify it under the
6 terms of the GNU Lesser General Public License as published by the Free Software
7 Foundation; either version 3, or (at your option) any later version.
8
9 Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License along with
14 Anastasis; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/>
15*/
16/**
17 * @file redux/validation_DE_TIN.c
18 * @brief validation logic for German taxpayer identification numbers
19 * @author Christian Grothoff
20 */
21#include <string.h>
22#include <stdbool.h>
23
24
25/**
26 * Function to validate a German Taxpayer identification number.
27 *
28 * See https://de.wikipedia.org/wiki/Steuerliche_Identifikationsnummer
29 * for the structure!
30 *
31 * @param tin_number tax number to validate (input)
32 * @return true if validation passed, else false
33 */
34bool
35DE_TIN_check (const char *tin_number)
36{
37 unsigned int csum;
38 unsigned int product = 10;
39
40 if (strlen (tin_number) != 11)
41 return false;
42 for (unsigned int i = 0; i<10; i++)
43 {
44 unsigned int sum = ((tin_number[i] - '0') + product) % 10;
45 if (0 == sum)
46 sum = 10;
47 product = sum * 2 % 11;
48 }
49 csum = 11 - product;
50 if (10 == csum)
51 csum = 0;
52 if (tin_number[10] != '0' + csum)
53 return false;
54 if (tin_number[0] == '0')
55 return false;
56 return true;
57}