diff options
Diffstat (limited to 'src/json')
-rw-r--r-- | src/json/json_wire.c | 13 | ||||
-rw-r--r-- | src/json/test_json_wire.c | 40 |
2 files changed, 41 insertions, 12 deletions
diff --git a/src/json/json_wire.c b/src/json/json_wire.c index 1cd3fd7d..7d3453e1 100644 --- a/src/json/json_wire.c +++ b/src/json/json_wire.c @@ -281,7 +281,15 @@ validate_iban (const char *iban) j++; } for (j = 0; '\0' != nbuf[j]; j++) - GNUNET_assert (isdigit ( (unsigned char) nbuf[j])); + { + if (! isdigit ( (unsigned char) nbuf[j])) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "IBAN `%s' didn't convert to numeric format\n", + iban); + return GNUNET_NO; + } + } GNUNET_assert (sizeof(dividend) >= 8); remainder = 0; for (unsigned int i = 0; i<j; i += 16) @@ -335,7 +343,8 @@ validate_payto_iban (const char *account_url) IBAN_PREFIX, strlen (IBAN_PREFIX))) return GNUNET_NO; - iban = &account_url[strlen (IBAN_PREFIX)]; + + iban = strrchr (account_url, '/') + 1; #undef IBAN_PREFIX q = strchr (iban, '?'); diff --git a/src/json/test_json_wire.c b/src/json/test_json_wire.c index 2725173b..75208c40 100644 --- a/src/json/test_json_wire.c +++ b/src/json/test_json_wire.c @@ -30,9 +30,12 @@ main (int argc, { struct TALER_MasterPublicKeyP master_pub; struct TALER_MasterPrivateKeyP master_priv; - json_t *wire; - const char *payto = "payto://x-taler-bank/42"; - char *p; + 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; @@ -42,15 +45,32 @@ main (int argc, GNUNET_CRYPTO_eddsa_key_create (&master_priv.eddsa_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); + 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, + TALER_JSON_exchange_wire_signature_check (wire_iban, &master_pub)); - json_decref (wire); + json_decref (wire_xtalerbank); + json_decref (wire_iban); return 0; } |