From 3526c44a38195aaea2ab48a220728df175ab9429 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 6 May 2016 18:33:02 +0200 Subject: refactor code to write signing keys in same module where we read them --- src/exchangedb/test_exchangedb_keyio.c | 59 +++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) (limited to 'src/exchangedb/test_exchangedb_keyio.c') diff --git a/src/exchangedb/test_exchangedb_keyio.c b/src/exchangedb/test_exchangedb_keyio.c index 2485da8ae..ab68f9cc2 100644 --- a/src/exchangedb/test_exchangedb_keyio.c +++ b/src/exchangedb/test_exchangedb_keyio.c @@ -14,8 +14,8 @@ TALER; see the file COPYING. If not, If not, see */ /** - * @file exchange/test_exchange_common.c - * @brief test cases for some functions in exchange/exchange_common.c + * @file exchangedb/test_exchangedb_keyio.c + * @brief test cases for some functions in exchangedb/exchangedb_keyio.c * @author Sree Harsha Totakura */ #include "platform.h" @@ -31,6 +31,47 @@ if (cond) { GNUNET_break (0); goto EXITIF_exit; } \ } while (0) +/** + * @brief Iterator called on denomination key. + * + * @param cls closure with expected DKI + * @param dki the denomination key + * @param alias coin alias + * @return #GNUNET_OK to continue to iterate, + * #GNUNET_NO to stop iteration with no error, + * #GNUNET_SYSERR to abort iteration with error! + */ +static int +dki_iter (void *cls, + const char *alias, + const struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki) +{ + const struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *exp = cls; + + if (0 != memcmp (&exp->issue, + &dki->issue, + sizeof (struct TALER_EXCHANGEDB_DenominationKeyInformationP))) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + if (0 != + GNUNET_CRYPTO_rsa_private_key_cmp (exp->denom_priv.rsa_private_key, + dki->denom_priv.rsa_private_key)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + if (0 != + GNUNET_CRYPTO_rsa_public_key_cmp (exp->denom_pub.rsa_public_key, + dki->denom_pub.rsa_public_key)) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } + return GNUNET_OK; +} + int main (int argc, @@ -59,8 +100,18 @@ main (int argc, enc_size = GNUNET_CRYPTO_rsa_private_key_encode (dki.denom_priv.rsa_private_key, &enc); EXITIF (NULL == (tmpfile = GNUNET_DISK_mktemp ("test_exchange_common"))); - EXITIF (GNUNET_OK != TALER_EXCHANGEDB_denomination_key_write (tmpfile, &dki)); - EXITIF (GNUNET_OK != TALER_EXCHANGEDB_denomination_key_read (tmpfile, &dki_read)); + EXITIF (GNUNET_OK != + TALER_EXCHANGEDB_denomination_key_write (tmpfile, + &dki)); + EXITIF (GNUNET_OK != + TALER_EXCHANGEDB_denomination_key_read (tmpfile, + &dki_read)); + EXITIF (1 != + TALER_EXCHANGEDB_denomination_keys_iterate (tmpfile, + &dki_iter, + &dki)); + + enc_read_size = GNUNET_CRYPTO_rsa_private_key_encode (dki_read.denom_priv.rsa_private_key, &enc_read); EXITIF (enc_size != enc_read_size); -- cgit v1.2.3