aboutsummaryrefslogtreecommitdiff
path: root/src/json/test_json_wire.c
blob: 75208c40aab4bc7ff883fd18f8f77568a66bae32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
  This file is part of TALER
  (C) 2015, 2016 Taler Systems SA

  TALER is free software; you can redistribute it and/or modify it under the
  terms of the GNU General Public License as published by the Free Software
  Foundation; either version 3, or (at your option) any later version.

  TALER 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
  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
*/

/**
 * @file json/test_json_wire.c
 * @brief Tests for Taler-specific crypto logic
 * @author Christian Grothoff <christian@grothoff.org>
 */
#include "platform.h"
#include "taler_util.h"
#include "taler_json_lib.h"


int
main (int argc,
      const char *const argv[])
{
  struct TALER_MasterPublicKeyP master_pub;
  struct TALER_MasterPrivateKeyP master_priv;
  json_t *wire_xtalerbank;
  json_t *wire_iban;
  const char *payto_xtalerbank = "payto://x-taler-bank/42";
  const char *payto_iban = "payto://iban/BIC-TO-BE-SKIPPED/DE89370400440532013000";
  char *p_xtalerbank;
  char *p_iban;

  (void) argc;
  (void) argv;
  GNUNET_log_setup ("test-json-wire",
                    "WARNING",
                    NULL);
  GNUNET_CRYPTO_eddsa_key_create (&master_priv.eddsa_priv);
  GNUNET_CRYPTO_eddsa_key_get_public (&master_priv.eddsa_priv,
                                      &master_pub.eddsa_pub);
  wire_xtalerbank = TALER_JSON_exchange_wire_signature_make (payto_xtalerbank,
                                                             &master_priv);
  wire_iban = TALER_JSON_exchange_wire_signature_make (payto_iban,
                                                       &master_priv);
  if (NULL == wire_iban)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "Could not parse payto/IBAN (%s) into 'wire object'\n",
                payto_iban);
    return 1;
  }
  p_xtalerbank = TALER_JSON_wire_to_payto (wire_xtalerbank);
  p_iban = TALER_JSON_wire_to_payto (wire_iban);
  GNUNET_assert (0 == strcmp (p_xtalerbank, payto_xtalerbank));
  GNUNET_assert (0 == strcmp (p_iban, payto_iban));
  GNUNET_free (p_xtalerbank);
  GNUNET_free (p_iban);

  GNUNET_assert (GNUNET_OK ==
                 TALER_JSON_exchange_wire_signature_check (wire_xtalerbank,
                                                           &master_pub));
  GNUNET_assert (GNUNET_OK ==
                 TALER_JSON_exchange_wire_signature_check (wire_iban,
                                                           &master_pub));
  json_decref (wire_xtalerbank);
  json_decref (wire_iban);

  return 0;
}


/* end of test_json_wire.c */