aboutsummaryrefslogtreecommitdiff
path: root/src/mint/test_mint_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mint/test_mint_common.c')
-rw-r--r--src/mint/test_mint_common.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/mint/test_mint_common.c b/src/mint/test_mint_common.c
new file mode 100644
index 000000000..b7cad3ea4
--- /dev/null
+++ b/src/mint/test_mint_common.c
@@ -0,0 +1,83 @@
1/*
2 This file is part of TALER
3 (C) 2014 GNUnet e. V. (and other contributing authors)
4
5 TALER is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3, or (at your option) any later version.
8
9 TALER 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 TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
15*/
16
17/**
18 * @file mint/test_mint_common.c
19 * @brief test cases for some functions in mint/mint_common.c
20 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
21 */
22
23#include "platform.h"
24#include "gnunet/gnunet_util_lib.h"
25#include "taler_rsa.h"
26#include "mint.h"
27
28#define EXITIF(cond) \
29 do { \
30 if (cond) { GNUNET_break (0); goto EXITIF_exit; } \
31 } while (0)
32
33int
34main (int argc, const char *const argv[])
35{
36 struct TALER_MINT_DenomKeyIssue dki;
37 struct TALER_RSA_PrivateKeyBinaryEncoded *enc;
38 struct TALER_MINT_DenomKeyIssue dki_read;
39 struct TALER_RSA_PrivateKeyBinaryEncoded *enc_read;
40 char *tmpfile;
41
42 int ret;
43
44 ret = 1;
45 enc = NULL;
46 enc_read = NULL;
47 tmpfile = NULL;
48 dki.denom_priv = NULL;
49 dki_read.denom_priv = NULL;
50 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
51 &dki.signature,
52 sizeof (dki) - offsetof (struct TALER_MINT_DenomKeyIssue,
53 signature));
54 dki.denom_priv = TALER_RSA_key_create ();
55 EXITIF (NULL == (enc = TALER_RSA_encode_key (dki.denom_priv)));
56 EXITIF (NULL == (tmpfile = GNUNET_DISK_mktemp ("test_mint_common")));
57 EXITIF (GNUNET_OK != TALER_MINT_write_denom_key (tmpfile, &dki));
58 EXITIF (GNUNET_OK != TALER_MINT_read_denom_key (tmpfile, &dki_read));
59 EXITIF (NULL == (enc_read = TALER_RSA_encode_key (dki_read.denom_priv)));
60 EXITIF (enc->len != enc_read->len);
61 EXITIF (0 != memcmp (enc,
62 enc_read,
63 ntohs(enc->len)));
64 EXITIF (0 != memcmp (&dki.signature,
65 &dki_read.signature,
66 sizeof (dki) - offsetof (struct TALER_MINT_DenomKeyIssue,
67 signature)));
68 ret = 0;
69
70 EXITIF_exit:
71 GNUNET_free_non_null (enc);
72 if (NULL != tmpfile)
73 {
74 (void) unlink (tmpfile);
75 GNUNET_free (tmpfile);
76 }
77 GNUNET_free_non_null (enc_read);
78 if (NULL != dki.denom_priv)
79 TALER_RSA_key_free (dki.denom_priv);
80 if (NULL != dki_read.denom_priv)
81 TALER_RSA_key_free (dki_read.denom_priv);
82 return ret;
83}