From 27457d94e4136d14c235aaea61214949842fc0aa Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 17 Jan 2020 17:46:13 +0100 Subject: use properly typed merchant pub/priv key in trait --- src/include/taler_testing_lib.h | 43 ++--- src/lib/Makefile.am | 2 +- .../testing_api_cmd_auditor_deposit_confirmation.c | 10 +- src/lib/testing_api_cmd_deposit.c | 4 +- src/lib/testing_api_cmd_refund.c | 49 +++--- src/lib/testing_api_cmd_track.c | 192 +++++++++++---------- src/lib/testing_api_trait_key_peer.c | 129 -------------- src/lib/testing_api_trait_merchant_key.c | 128 ++++++++++++++ 8 files changed, 276 insertions(+), 281 deletions(-) delete mode 100644 src/lib/testing_api_trait_key_peer.c create mode 100644 src/lib/testing_api_trait_merchant_key.c diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h index 338eea654..ffe785658 100644 --- a/src/include/taler_testing_lib.h +++ b/src/include/taler_testing_lib.h @@ -2139,7 +2139,7 @@ struct TALER_TESTING_FreshCoinData * Offer a _array_ of fresh coins. * * @param index which array of fresh coins to offer, - * if there are multiple on offer. Tipically passed as + * if there are multiple on offer. Typically passed as * zero. * @param fresh_coins the array of fresh coins to offer * @@ -2255,74 +2255,69 @@ TALER_TESTING_make_trait_exchange_keys (unsigned int index, /** - * Obtain a private key from a "peer". Used e.g. to obtain + * Obtain a private key from a "merchant". Used e.g. to obtain * a merchant's priv to sign a /track request. * * @param cmd command that is offering the key. - * @param index (tipically zero) which key to return if there + * @param index (typically zero) which key to return if there * are multiple on offer. * @param priv[out] set to the key coming from @a cmd. * @return #GNUNET_OK on success. */ int -TALER_TESTING_get_trait_peer_key (const struct TALER_TESTING_Command *cmd, - unsigned int index, - const struct - GNUNET_CRYPTO_EddsaPrivateKey **priv); +TALER_TESTING_get_trait_merchant_priv (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const struct + TALER_MerchantPrivateKeyP **priv); // FIXME: private get_trait_merchant_priv instead, rather have // more traits with precise types than this! /** - * Offer private key, typically done when CMD_1 needs it to + * Offer private key of a merchant, typically done when CMD_1 needs it to * sign a request. * - * @param index (tipically zero) which key to return if there are + * @param index (typically zero) which key to return if there are * multiple on offer. * @param priv which object should be offered. * @return the trait. */ struct TALER_TESTING_Trait -TALER_TESTING_make_trait_peer_key (unsigned int index, - const struct - GNUNET_CRYPTO_EddsaPrivateKey *priv); - -// FIXME: private get_trait_merchant_priv instead, rather have -// more traits with precise types than this! +TALER_TESTING_make_trait_merchant_priv (unsigned int index, + const struct + TALER_MerchantPrivateKeyP *priv); /** - * Obtain a public key from a "peer". Used e.g. to obtain + * Obtain a public key from a "merchant". Used e.g. to obtain * a merchant's public key to use backend's API. * * @param cmd command offering the key. - * @param index (tipically zero) which key to return if there + * @param index (typically zero) which key to return if there * are multiple on offer. * @param pub[out] set to the key coming from @a cmd. - * * @return #GNUNET_OK on success. */ int -TALER_TESTING_get_trait_peer_key_pub (const struct TALER_TESTING_Command *cmd, +TALER_TESTING_get_trait_merchant_pub (const struct TALER_TESTING_Command *cmd, unsigned int index, const struct - GNUNET_CRYPTO_EddsaPublicKey **pub); + TALER_MerchantPublicKeyP **pub); /** * Offer public key. * - * @param index (tipically zero) which key to return if there + * @param index (typically zero) which key to return if there * are multiple on offer. NOTE: if one key is offered, it * is mandatory to set this as zero. * @param pub which object should be returned. - * * @return the trait. */ struct TALER_TESTING_Trait -TALER_TESTING_make_trait_peer_key_pub (unsigned int index, - struct GNUNET_CRYPTO_EddsaPublicKey *pub); +TALER_TESTING_make_trait_merchant_pub (unsigned int index, + struct TALER_MerchantPublicKeyP *pub); /** diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index ba1a56259..a3b680032 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -114,7 +114,7 @@ libtalertesting_la_SOURCES = \ testing_api_trait_exchange_sig.c \ testing_api_trait_fresh_coin.c \ testing_api_trait_json.c \ - testing_api_trait_key_peer.c \ + testing_api_trait_merchant_key.c \ testing_api_trait_number.c \ testing_api_trait_process.c \ testing_api_trait_reserve_pub.c \ diff --git a/src/lib/testing_api_cmd_auditor_deposit_confirmation.c b/src/lib/testing_api_cmd_auditor_deposit_confirmation.c index 3ea6390d8..84fba1b30 100644 --- a/src/lib/testing_api_cmd_auditor_deposit_confirmation.c +++ b/src/lib/testing_api_cmd_auditor_deposit_confirmation.c @@ -197,7 +197,7 @@ deposit_confirmation_run (void *cls, struct GNUNET_TIME_Absolute refund_deadline; struct TALER_Amount amount_without_fee; struct TALER_CoinSpendPublicKeyP coin_pub; - const struct GNUNET_CRYPTO_EddsaPrivateKey *merchant_priv; + const struct TALER_MerchantPrivateKeyP *merchant_priv; struct TALER_MerchantPublicKeyP merchant_pub; const struct TALER_ExchangePublicKeyP *exchange_pub; const struct TALER_ExchangeSignatureP *exchange_sig; @@ -255,10 +255,10 @@ deposit_confirmation_run (void *cls, GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv, &coin_pub.eddsa_pub); GNUNET_assert (GNUNET_OK == - TALER_TESTING_get_trait_peer_key (deposit_cmd, - dcs->coin_index, - &merchant_priv)); - GNUNET_CRYPTO_eddsa_key_get_public (merchant_priv, + TALER_TESTING_get_trait_merchant_priv (deposit_cmd, + dcs->coin_index, + &merchant_priv)); + GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv->eddsa_priv, &merchant_pub.eddsa_pub); GNUNET_assert (GNUNET_OK == TALER_string_to_amount (dcs->amount_without_fee, diff --git a/src/lib/testing_api_cmd_deposit.c b/src/lib/testing_api_cmd_deposit.c index 531807fa3..b0361c61f 100644 --- a/src/lib/testing_api_cmd_deposit.c +++ b/src/lib/testing_api_cmd_deposit.c @@ -446,8 +446,8 @@ deposit_traits (void *cls, ds->wire_details), TALER_TESTING_make_trait_contract_terms (0, ds->contract_terms), - TALER_TESTING_make_trait_peer_key (0, - &ds->merchant_priv.eddsa_priv), + TALER_TESTING_make_trait_merchant_priv (0, + &ds->merchant_priv), TALER_TESTING_make_trait_amount_obj (0, &ds->amount), TALER_TESTING_trait_end () diff --git a/src/lib/testing_api_cmd_refund.c b/src/lib/testing_api_cmd_refund.c index 91085f364..da4611b40 100644 --- a/src/lib/testing_api_cmd_refund.c +++ b/src/lib/testing_api_cmd_refund.c @@ -16,14 +16,12 @@ License along with TALER; see the file COPYING. If not, see */ - /** * @file exchange/testing_api_cmd_refund.c * @brief Implement the /refund test command, plus other * corollary commands (?). * @author Marcello Stanisci */ - #include "platform.h" #include "taler_json_lib.h" #include @@ -137,7 +135,7 @@ refund_run (void *cls, struct GNUNET_HashCode h_contract_terms; struct TALER_Amount refund_fee; struct TALER_Amount refund_amount; - const struct GNUNET_CRYPTO_EddsaPrivateKey *merchant_priv; + const struct TALER_MerchantPrivateKeyP *merchant_priv; const struct TALER_TESTING_Command *coin_cmd; rs->exchange = is->exchange; @@ -168,31 +166,32 @@ refund_run (void *cls, return; } - coin_cmd = TALER_TESTING_interpreter_lookup_command - (is, rs->coin_reference); - + coin_cmd = TALER_TESTING_interpreter_lookup_command (is, + rs->coin_reference); if (NULL == coin_cmd) { GNUNET_break (0); TALER_TESTING_interpreter_fail (is); return; } - - if (GNUNET_OK != TALER_TESTING_get_trait_contract_terms - (coin_cmd, 0, &contract_terms)) + if (GNUNET_OK != + TALER_TESTING_get_trait_contract_terms (coin_cmd, + 0, + &contract_terms)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (is); return; } - GNUNET_assert (GNUNET_OK == TALER_JSON_hash (contract_terms, &h_contract_terms)); /* Hunting for a coin .. */ - if (GNUNET_OK != TALER_TESTING_get_trait_coin_priv - (coin_cmd, 0, &coin_priv)) + if (GNUNET_OK != + TALER_TESTING_get_trait_coin_priv (coin_cmd, + 0, + &coin_priv)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (is); @@ -201,24 +200,24 @@ refund_run (void *cls, GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv, &coin.eddsa_pub); - if (GNUNET_OK != TALER_TESTING_get_trait_peer_key - (coin_cmd, 0, &merchant_priv)) + if (GNUNET_OK != + TALER_TESTING_get_trait_merchant_priv (coin_cmd, + 0, + &merchant_priv)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (is); return; } - - rs->rh = TALER_EXCHANGE_refund - (rs->exchange, - &refund_amount, - &refund_fee, - &h_contract_terms, - &coin, - rs->refund_transaction_id, - (const struct TALER_MerchantPrivateKeyP *) merchant_priv, - &refund_cb, rs); - + rs->rh = TALER_EXCHANGE_refund (rs->exchange, + &refund_amount, + &refund_fee, + &h_contract_terms, + &coin, + rs->refund_transaction_id, + merchant_priv, + &refund_cb, + rs); GNUNET_assert (NULL != rs->rh); } diff --git a/src/lib/testing_api_cmd_track.c b/src/lib/testing_api_cmd_track.c index 8784e686c..1de6c1929 100644 --- a/src/lib/testing_api_cmd_track.c +++ b/src/lib/testing_api_cmd_track.c @@ -156,15 +156,14 @@ struct TrackTransferState * if @a http_status is #MHD_HTTP_OK). */ static void -deposit_wtid_cb - (void *cls, - unsigned int http_status, - enum TALER_ErrorCode ec, - const struct TALER_ExchangePublicKeyP *exchange_pub, - const json_t *json, - const struct TALER_WireTransferIdentifierRawP *wtid, - struct GNUNET_TIME_Absolute execution_time, - const struct TALER_Amount *coin_contribution) +deposit_wtid_cb (void *cls, + unsigned int http_status, + enum TALER_ErrorCode ec, + const struct TALER_ExchangePublicKeyP *exchange_pub, + const json_t *json, + const struct TALER_WireTransferIdentifierRawP *wtid, + struct GNUNET_TIME_Absolute execution_time, + const struct TALER_Amount *coin_contribution) { struct TrackTransactionState *tts = cls; struct TALER_TESTING_Interpreter *is = tts->is; @@ -255,12 +254,12 @@ track_transaction_run (void *cls, const json_t *wire_details; struct GNUNET_HashCode h_wire_details; struct GNUNET_HashCode h_contract_terms; - const struct GNUNET_CRYPTO_EddsaPrivateKey *merchant_priv; + const struct TALER_MerchantPrivateKeyP *merchant_priv; tts->is = is; - transaction_cmd = TALER_TESTING_interpreter_lookup_command - (tts->is, tts->transaction_reference); - + transaction_cmd + = TALER_TESTING_interpreter_lookup_command (tts->is, + tts->transaction_reference); if (NULL == transaction_cmd) { GNUNET_break (0); @@ -268,8 +267,10 @@ track_transaction_run (void *cls, return; } - if (GNUNET_OK != TALER_TESTING_get_trait_coin_priv - (transaction_cmd, tts->coin_index, &coin_priv)) + if (GNUNET_OK != + TALER_TESTING_get_trait_coin_priv (transaction_cmd, + tts->coin_index, + &coin_priv)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (tts->is); @@ -280,23 +281,28 @@ track_transaction_run (void *cls, &coin_pub.eddsa_pub); /* Get the strings.. */ - if (GNUNET_OK != TALER_TESTING_get_trait_wire_details - (transaction_cmd, 0, &wire_details)) + if (GNUNET_OK != + TALER_TESTING_get_trait_wire_details (transaction_cmd, + 0, + &wire_details)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (tts->is); return; } - if (GNUNET_OK != TALER_TESTING_get_trait_contract_terms - (transaction_cmd, 0, &contract_terms)) + if (GNUNET_OK != + TALER_TESTING_get_trait_contract_terms (transaction_cmd, + 0, + &contract_terms)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (tts->is); return; } - if ((NULL == wire_details) || (NULL == contract_terms)) + if ( (NULL == wire_details) || + (NULL == contract_terms) ) { GNUNET_break (0); TALER_TESTING_interpreter_fail (tts->is); @@ -312,23 +318,23 @@ track_transaction_run (void *cls, TALER_JSON_hash (contract_terms, &h_contract_terms)) ); - if (GNUNET_OK != TALER_TESTING_get_trait_peer_key - (transaction_cmd, 0, &merchant_priv)) + if (GNUNET_OK != + TALER_TESTING_get_trait_merchant_priv (transaction_cmd, + 0, + &merchant_priv)) { GNUNET_break (0); TALER_TESTING_interpreter_fail (tts->is); return; } - tts->tth = TALER_EXCHANGE_track_transaction - (is->exchange, - (struct TALER_MerchantPrivateKeyP *) merchant_priv, - &h_wire_details, - &h_contract_terms, - &coin_pub, - &deposit_wtid_cb, - tts); - + tts->tth = TALER_EXCHANGE_track_transaction (is->exchange, + merchant_priv, + &h_wire_details, + &h_contract_terms, + &coin_pub, + &deposit_wtid_cb, + tts); GNUNET_assert (NULL != tts->tth); } @@ -341,9 +347,8 @@ track_transaction_run (void *cls, * @param cmd the command which is being cleaned up. */ static void -track_transaction_cleanup - (void *cls, - const struct TALER_TESTING_Command *cmd) +track_transaction_cleanup (void *cls, + const struct TALER_TESTING_Command *cmd) { struct TrackTransactionState *tts = cls; @@ -404,12 +409,11 @@ track_transaction_traits (void *cls, * @return the command. */ struct TALER_TESTING_Command -TALER_TESTING_cmd_track_transaction - (const char *label, - const char *transaction_reference, - unsigned int coin_index, - unsigned int expected_response_code, - const char *bank_transfer_reference) +TALER_TESTING_cmd_track_transaction (const char *label, + const char *transaction_reference, + unsigned int coin_index, + unsigned int expected_response_code, + const char *bank_transfer_reference) { struct TrackTransactionState *tts; @@ -418,16 +422,17 @@ TALER_TESTING_cmd_track_transaction tts->expected_response_code = expected_response_code; tts->bank_transfer_reference = bank_transfer_reference; tts->coin_index = coin_index; - - struct TALER_TESTING_Command cmd = { - .cls = tts, - .label = label, - .run = &track_transaction_run, - .cleanup = &track_transaction_cleanup, - .traits = &track_transaction_traits - }; - - return cmd; + { + struct TALER_TESTING_Command cmd = { + .cls = tts, + .label = label, + .run = &track_transaction_run, + .cleanup = &track_transaction_cleanup, + .traits = &track_transaction_traits + }; + + return cmd; + } } @@ -483,18 +488,17 @@ track_transfer_cleanup (void *cls, * transactions. */ static void -track_transfer_cb - (void *cls, - unsigned int http_status, - enum TALER_ErrorCode ec, - const struct TALER_ExchangePublicKeyP *exchange_pub, - const json_t *json, - const struct GNUNET_HashCode *h_wire, - struct GNUNET_TIME_Absolute execution_time, - const struct TALER_Amount *total_amount, - const struct TALER_Amount *wire_fee, - unsigned int details_length, - const struct TALER_TrackTransferDetails *details) +track_transfer_cb (void *cls, + unsigned int http_status, + enum TALER_ErrorCode ec, + const struct TALER_ExchangePublicKeyP *exchange_pub, + const json_t *json, + const struct GNUNET_HashCode *h_wire, + struct GNUNET_TIME_Absolute execution_time, + const struct TALER_Amount *total_amount, + const struct TALER_Amount *wire_fee, + unsigned int details_length, + const struct TALER_TrackTransferDetails *details) { struct TrackTransferState *tts = cls; struct TALER_TESTING_Interpreter *is = tts->is; @@ -668,7 +672,7 @@ track_transfer_cb * @param cmd the command under execution. * @param is the interpreter state. */ -void +static void track_transfer_run (void *cls, const struct TALER_TESTING_Command *cmd, struct TALER_TESTING_Interpreter *is) @@ -733,28 +737,27 @@ track_transfer_run (void *cls, * @return the command. */ struct TALER_TESTING_Command -TALER_TESTING_cmd_track_transfer_empty - (const char *label, - const char *wtid_reference, - unsigned int index, - unsigned int expected_response_code) +TALER_TESTING_cmd_track_transfer_empty (const char *label, + const char *wtid_reference, + unsigned int index, + unsigned int expected_response_code) { struct TrackTransferState *tts; tts = GNUNET_new (struct TrackTransferState); - tts->wtid_reference = wtid_reference; tts->index = index; tts->expected_response_code = expected_response_code; - - struct TALER_TESTING_Command cmd = { - .cls = tts, - .label = label, - .run = &track_transfer_run, - .cleanup = &track_transfer_cleanup - }; - - return cmd; + { + struct TALER_TESTING_Command cmd = { + .cls = tts, + .label = label, + .run = &track_transfer_run, + .cleanup = &track_transfer_cleanup + }; + + return cmd; + } } @@ -775,32 +778,31 @@ TALER_TESTING_cmd_track_transfer_empty * @return the command */ struct TALER_TESTING_Command -TALER_TESTING_cmd_track_transfer - (const char *label, - const char *wtid_reference, - unsigned int index, - unsigned int expected_response_code, - const char *expected_total_amount, - const char *expected_wire_fee) +TALER_TESTING_cmd_track_transfer (const char *label, + const char *wtid_reference, + unsigned int index, + unsigned int expected_response_code, + const char *expected_total_amount, + const char *expected_wire_fee) { struct TrackTransferState *tts; tts = GNUNET_new (struct TrackTransferState); - tts->wtid_reference = wtid_reference; tts->index = index; tts->expected_response_code = expected_response_code; tts->expected_total_amount = expected_total_amount; tts->expected_wire_fee = expected_wire_fee; - - struct TALER_TESTING_Command cmd = { - .cls = tts, - .label = label, - .run = &track_transfer_run, - .cleanup = &track_transfer_cleanup - }; - - return cmd; + { + struct TALER_TESTING_Command cmd = { + .cls = tts, + .label = label, + .run = &track_transfer_run, + .cleanup = &track_transfer_cleanup + }; + + return cmd; + } } diff --git a/src/lib/testing_api_trait_key_peer.c b/src/lib/testing_api_trait_key_peer.c deleted file mode 100644 index e5d1e82f2..000000000 --- a/src/lib/testing_api_trait_key_peer.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2018 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 - -*/ - -/** - * @file exchange-lib/testing_api_trait_key_peer.c - * @brief traits to offer peer's (private) keys - * @author Marcello Stanisci - */ -#include "platform.h" -#include "taler_json_lib.h" -#include -#include "exchange_api_handle.h" -#include "taler_signatures.h" -#include "taler_testing_lib.h" - -#define TALER_TESTING_TRAIT_KEY_PEER "key-peer" -#define TALER_TESTING_TRAIT_KEY_PEER_PUB "key-peer-pub" - -/** - * Obtain a private key from a "peer". Used e.g. to obtain - * a merchant's priv to sign a /track request. - * - * @param cmd command that is offering the key. - * @param index (tipically zero) which key to return if there - * are multiple on offer. - * @param priv[out] set to the key coming from @a cmd. - * @return #GNUNET_OK on success. - */ -int -TALER_TESTING_get_trait_peer_key - (const struct TALER_TESTING_Command *cmd, - unsigned int index, - const struct GNUNET_CRYPTO_EddsaPrivateKey **priv) -{ - return cmd->traits (cmd->cls, - (const void **) priv, - TALER_TESTING_TRAIT_KEY_PEER, - index); -} - - -/** - * Offer private key, typically done when CMD_1 needs it to - * sign a request. - * - * @param index (tipically zero) which key to return if there are - * multiple on offer. - * @param priv which object should be offered. - * @return the trait. - */ -struct TALER_TESTING_Trait -TALER_TESTING_make_trait_peer_key - (unsigned int index, - const struct GNUNET_CRYPTO_EddsaPrivateKey *priv) -{ - struct TALER_TESTING_Trait ret = { - .index = index, - .trait_name = TALER_TESTING_TRAIT_KEY_PEER, - .ptr = (const void *) priv - }; - return ret; -} - - -/** - * Obtain a public key from a "peer". Used e.g. to obtain - * a merchant's public key to use backend's API. - * - * @param cmd command offering the key. - * @param index (tipically zero) which key to return if there - * are multiple on offer. - * @param pub[out] set to the key coming from @a cmd. - * - * @return #GNUNET_OK on success. - */ -int -TALER_TESTING_get_trait_peer_key_pub - (const struct TALER_TESTING_Command *cmd, - unsigned int index, - const struct GNUNET_CRYPTO_EddsaPublicKey **pub) -{ - return cmd->traits (cmd->cls, - (const void **) pub, - TALER_TESTING_TRAIT_KEY_PEER_PUB, - index); -} - - -/** - * Offer public key. - * - * @param index (tipically zero) which key to return if there - * are multiple on offer. NOTE: if one key is offered, it - * is mandatory to set this as zero. - * @param pub which object should be returned. - * - * @return the trait. - */ -struct TALER_TESTING_Trait -TALER_TESTING_make_trait_peer_key_pub - (unsigned int index, - struct GNUNET_CRYPTO_EddsaPublicKey *pub) -{ - struct TALER_TESTING_Trait ret = { - .index = index, - .trait_name = TALER_TESTING_TRAIT_KEY_PEER_PUB, - .ptr = (const void *) pub - }; - return ret; -} - - -/* end of testing_api_trait_key_peer.c */ diff --git a/src/lib/testing_api_trait_merchant_key.c b/src/lib/testing_api_trait_merchant_key.c new file mode 100644 index 000000000..d39a59247 --- /dev/null +++ b/src/lib/testing_api_trait_merchant_key.c @@ -0,0 +1,128 @@ +/* + This file is part of TALER + Copyright (C) 2018 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 + +*/ +/** + * @file lib/testing_api_trait_merchant_key.c + * @brief traits to offer peer's (private) keys + * @author Marcello Stanisci + */ +#include "platform.h" +#include "taler_json_lib.h" +#include +#include "exchange_api_handle.h" +#include "taler_signatures.h" +#include "taler_testing_lib.h" + +#define TALER_TESTING_TRAIT_MERCHANT_PRIV "merchant-priv" +#define TALER_TESTING_TRAIT_MERCHANT_PUB "merchant-pub-pub" + +/** + * Obtain a private key from a "peer". Used e.g. to obtain + * a merchant's priv to sign a /track request. + * + * @param cmd command that is offering the key. + * @param index (typically zero) which key to return if there + * are multiple on offer. + * @param priv[out] set to the key coming from @a cmd. + * @return #GNUNET_OK on success. + */ +int +TALER_TESTING_get_trait_merchant_priv + (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const struct TALER_MerchantPrivateKeyP **priv) +{ + return cmd->traits (cmd->cls, + (const void **) priv, + TALER_TESTING_TRAIT_MERCHANT_PRIV, + index); +} + + +/** + * Offer private key, typically done when CMD_1 needs it to + * sign a request. + * + * @param index (typically zero) which key to return if there are + * multiple on offer. + * @param priv which object should be offered. + * @return the trait. + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_merchant_priv (unsigned int index, + const struct + TALER_MerchantPrivateKeyP *priv) +{ + struct TALER_TESTING_Trait ret = { + .index = index, + .trait_name = TALER_TESTING_TRAIT_MERCHANT_PRIV, + .ptr = (const void *) priv + }; + + return ret; +} + + +/** + * Obtain a public key from a "peer". Used e.g. to obtain + * a merchant's public key to use backend's API. + * + * @param cmd command offering the key. + * @param index (typically zero) which key to return if there + * are multiple on offer. + * @param pub[out] set to the key coming from @a cmd. + * + * @return #GNUNET_OK on success. + */ +int +TALER_TESTING_get_trait_merchant_pub + (const struct TALER_TESTING_Command *cmd, + unsigned int index, + const struct TALER_MerchantPublicKeyP **pub) +{ + return cmd->traits (cmd->cls, + (const void **) pub, + TALER_TESTING_TRAIT_MERCHANT_PUB, + index); +} + + +/** + * Offer public key. + * + * @param index (typically zero) which key to return if there + * are multiple on offer. NOTE: if one key is offered, it + * is mandatory to set this as zero. + * @param pub which object should be returned. + * @return the trait. + */ +struct TALER_TESTING_Trait +TALER_TESTING_make_trait_merchant_pub (unsigned int index, + struct TALER_MerchantPublicKeyP *pub) +{ + struct TALER_TESTING_Trait ret = { + .index = index, + .trait_name = TALER_TESTING_TRAIT_MERCHANT_PUB, + .ptr = (const void *) pub + }; + + return ret; +} + + +/* end of testing_api_trait_merchant_key.c */ -- cgit v1.2.3