From 9a5030b993d74732f8fba2879cfca03ec070ad9a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 26 Jun 2019 20:43:08 +0200 Subject: add test for json_wire.c logic --- src/json/test_json_wire.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/json/test_json_wire.c (limited to 'src/json/test_json_wire.c') diff --git a/src/json/test_json_wire.c b/src/json/test_json_wire.c new file mode 100644 index 000000000..9e59dfa8a --- /dev/null +++ b/src/json/test_json_wire.c @@ -0,0 +1,59 @@ +/* + This file is part of TALER + (C) 2015, 2016 GNUnet e.V. and Inria + + 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 +*/ + +/** + * @file json/test_json_wire.c + * @brief Tests for Taler-specific crypto logic + * @author Christian Grothoff + */ +#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 GNUNET_CRYPTO_EddsaPrivateKey *priv; + struct TALER_MasterPrivateKeyP master_priv; + json_t *wire; + const char *payto = "payto://x-taler-bank/42"; + char *p; + + GNUNET_log_setup ("test-json-wire", + "WARNING", + NULL); + priv = GNUNET_CRYPTO_eddsa_key_create (); + master_priv.eddsa_priv = *priv; + GNUNET_free (priv); + GNUNET_CRYPTO_eddsa_key_get_public (&master_priv.eddsa_priv, + &master_pub.eddsa_pub); + wire = TALER_JSON_exchange_wire_signature_make (payto, + &master_priv); + p = TALER_JSON_wire_to_payto (wire); + GNUNET_assert (0 == strcmp (p, payto)); + GNUNET_free (p); + GNUNET_assert (GNUNET_OK == + TALER_JSON_exchange_wire_signature_check (wire, + &master_pub)); + json_decref (wire); + + return 0; +} + +/* end of test_json_wire.c */ -- cgit v1.2.3