LCOV - code coverage report
Current view: top level - exchangedb - perf_taler_exchangedb_init.c (source / functions) Hit Total Coverage
Test: rcoverage.info Lines: 167 227 73.6 %
Date: 2017-11-25 11:31:41 Functions: 12 21 57.1 %

          Line data    Source code
       1             : /*
       2             :    This file is part of TALER
       3             :    Copyright (C) 2014, 2015, 2016 Inria & GNUnet e.V.
       4             : 
       5             :    TALER is free software; you can redistribute it and/or modify it under the
       6             :    terms of the GNU General Public License as published by the Free Software
       7             :    Foundation; either version 3, or (at your option) any later version.
       8             : 
       9             :    TALER is distributed in the hope that it will be useful, but WITHOUT ANY
      10             :    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
      11             :    A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
      12             : 
      13             :    You should have received a copy of the GNU General Public License along with
      14             :    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
      15             :    */
      16             : /**
      17             :  * @file exchangedb/perf_taler_exchangedb_init.c
      18             :  * @brief Interpreter library for exchange database performance analysis
      19             :  * @author Nicolas Fournier
      20             :  * @author Christian Grothoff
      21             :  */
      22             : #include "platform.h"
      23             : #include "perf_taler_exchangedb_init.h"
      24             : #include <gnunet/gnunet_signatures.h>
      25             : #include "taler_signatures.h"
      26             : #include "taler_amount_lib.h"
      27             : 
      28             : 
      29             : #define CURRENCY "EUR"
      30             : #define PERF_TALER_EXCHANGEDB_RSA_SIZE 512
      31             : 
      32             : 
      33             : /**
      34             :  * Generate a dummy DenominationKeyInformation for testing purposes
      35             :  * @return a dummy denomination key
      36             :  */
      37             : struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *
      38           3 : PERF_TALER_EXCHANGEDB_denomination_init ()
      39             : {
      40             :   struct GNUNET_CRYPTO_EddsaPrivateKey *master_prvt;
      41             :   struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki;
      42             :   struct TALER_DenominationPrivateKey denom_priv;
      43             :   struct TALER_DenominationPublicKey denom_pub;
      44             :   struct TALER_EXCHANGEDB_DenominationKeyInformationP issue;
      45             : 
      46           3 :   master_prvt = GNUNET_CRYPTO_eddsa_key_create();
      47             : 
      48           3 :   dki = GNUNET_new (struct TALER_EXCHANGEDB_DenominationKeyIssueInformation);
      49           3 :   GNUNET_assert (NULL != dki);
      50             :   denom_priv.rsa_private_key
      51           3 :     = GNUNET_CRYPTO_rsa_private_key_create (PERF_TALER_EXCHANGEDB_RSA_SIZE);
      52           3 :   GNUNET_assert (NULL != denom_priv.rsa_private_key);
      53           3 :   denom_pub.rsa_public_key =
      54           3 :     GNUNET_CRYPTO_rsa_private_key_get_public (denom_priv.rsa_private_key);
      55           3 :   GNUNET_assert (NULL != denom_pub.rsa_public_key);
      56             :   {/* issue */
      57             :     struct TALER_MasterSignatureP signature;
      58             :     struct TALER_DenominationKeyValidityPS properties;
      59             : 
      60             :     {/* properties */
      61             :       struct TALER_Amount amount;
      62             : 
      63           3 :       properties.purpose.purpose = htonl (TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY);
      64           3 :       properties.purpose.size = htonl (sizeof (struct TALER_DenominationKeyValidityPS));
      65           3 :       GNUNET_CRYPTO_eddsa_key_get_public (master_prvt,
      66             :                                           &properties.master.eddsa_pub);
      67           3 :       properties.start = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get());
      68           3 :       properties.expire_withdraw = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_forever_());
      69           3 :       properties.expire_deposit = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_forever_());
      70           3 :       properties.expire_legal = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_forever_());
      71           3 :       GNUNET_assert (GNUNET_OK ==
      72             :                      TALER_string_to_amount (CURRENCY ":1.1", &amount));
      73           3 :       TALER_amount_hton (&properties.value, &amount);
      74           3 :       GNUNET_assert (GNUNET_OK ==
      75             :                      TALER_string_to_amount (CURRENCY ":0.1", &amount));
      76           3 :       TALER_amount_hton (&properties.fee_withdraw, &amount);
      77           3 :       TALER_amount_hton (&properties.fee_deposit, &amount);
      78           3 :       TALER_amount_hton (&properties.fee_refresh, &amount);
      79           3 :       TALER_amount_hton (&properties.fee_refund, &amount);
      80           3 :       GNUNET_CRYPTO_rsa_public_key_hash (denom_pub.rsa_public_key,
      81             :                                          &properties.denom_hash);
      82           3 :       issue.properties = properties;
      83             :     }
      84             :     {/* signature */
      85           3 :       GNUNET_CRYPTO_eddsa_sign (master_prvt,
      86             :                                 &properties.purpose,
      87             :                                 &signature.eddsa_signature);
      88           3 :       issue.signature = signature;
      89             :     }
      90             :   }
      91           3 :   dki->denom_priv = denom_priv;
      92           3 :   dki->denom_pub = denom_pub;
      93           3 :   dki->issue = issue;
      94           3 :   GNUNET_free (master_prvt);
      95           3 :   return dki;
      96             : }
      97             : 
      98             : 
      99             : /**
     100             :  * Copies the given denomination
     101             :  * @param reserve the deposit copy
     102             :  * @return a copy of @a deposit; NULL if error
     103             :  */
     104             : struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *
     105           4 : PERF_TALER_EXCHANGEDB_denomination_copy (const struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki)
     106             : {
     107             :   struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *copy;
     108             : 
     109           4 :   GNUNET_assert (NULL !=
     110             :                  (copy = GNUNET_new (struct TALER_EXCHANGEDB_DenominationKeyIssueInformation)));
     111             :   {/* denom_priv */
     112           4 :     copy->denom_priv.rsa_private_key =
     113           4 :       GNUNET_CRYPTO_rsa_private_key_dup ( dki->denom_priv.rsa_private_key);
     114             :   }
     115             :   {/* denom_pub */
     116           4 :     copy->denom_pub.rsa_public_key =
     117           4 :       GNUNET_CRYPTO_rsa_public_key_dup (dki->denom_pub.rsa_public_key);
     118             :   }
     119             :   {/* issue */
     120           4 :     copy->issue.properties = dki->issue.properties;
     121           4 :     copy->issue.signature = dki->issue.signature;
     122             :   }
     123           4 :   return copy;
     124             : }
     125             : 
     126             : 
     127             : /**
     128             :  * Free memory of a DenominationKeyIssueInformation
     129             :  * @param dki pointer to the struct to free
     130             :  */
     131             : int
     132           7 : PERF_TALER_EXCHANGEDB_denomination_free (struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki)
     133             : {
     134           7 :   if (NULL == dki)
     135           0 :     return GNUNET_OK;
     136           7 :   GNUNET_CRYPTO_rsa_private_key_free (dki->denom_priv.rsa_private_key);
     137           7 :   GNUNET_CRYPTO_rsa_public_key_free (dki->denom_pub.rsa_public_key);
     138             : 
     139           7 :   GNUNET_free (dki);
     140           7 :   return GNUNET_OK;
     141             : }
     142             : 
     143             : 
     144             : /**
     145             :  * Generate a dummy reserve for testing
     146             :  * @return a reserve with 1000 EUR in it
     147             :  */
     148             : struct PERF_TALER_EXCHANGEDB_Reserve *
     149           5 : PERF_TALER_EXCHANGEDB_reserve_init ()
     150             : {
     151             :   struct PERF_TALER_EXCHANGEDB_Reserve *reserve;
     152             : 
     153           5 :   GNUNET_assert (NULL !=
     154             :                  (reserve = GNUNET_new (struct PERF_TALER_EXCHANGEDB_Reserve)));
     155             :   {/* private */
     156             :     struct GNUNET_CRYPTO_EddsaPrivateKey *private;
     157           5 :     private = GNUNET_CRYPTO_eddsa_key_create ();
     158           5 :     GNUNET_assert (NULL != private);
     159           5 :     reserve->private = *private;
     160           5 :     GNUNET_free (private);
     161             :   }
     162             : 
     163           5 :   GNUNET_CRYPTO_eddsa_key_get_public (&reserve->private,
     164             :                                       &reserve->reserve.pub.eddsa_pub);
     165           5 :   GNUNET_assert (GNUNET_OK ==
     166             :                  TALER_string_to_amount (CURRENCY ":1000", &reserve->reserve.balance));
     167           5 :   reserve->reserve.expiry = GNUNET_TIME_absolute_get_forever_ ();
     168           5 :   return reserve;
     169             : }
     170             : 
     171             : 
     172             : /**
     173             :  * Copies the given reserve
     174             :  * @param reserve the reserve to copy
     175             :  * @return a copy of @a reserve; NULL if error
     176             :  */
     177             : struct PERF_TALER_EXCHANGEDB_Reserve *
     178           3 : PERF_TALER_EXCHANGEDB_reserve_copy (const struct PERF_TALER_EXCHANGEDB_Reserve *reserve)
     179             : {
     180             :   struct PERF_TALER_EXCHANGEDB_Reserve *copy;
     181           3 :   GNUNET_assert (NULL !=
     182             :                  (copy = GNUNET_new (struct PERF_TALER_EXCHANGEDB_Reserve)));
     183           3 :   *copy = *reserve;
     184           3 :   return copy;
     185             : }
     186             : 
     187             : 
     188             : /**
     189             :  * Free memory of a reserve
     190             :  * @param reserve pointer to the structure to be freed
     191             :  */
     192             : int
     193           8 : PERF_TALER_EXCHANGEDB_reserve_free (struct PERF_TALER_EXCHANGEDB_Reserve *reserve)
     194             : {
     195           8 :   if (NULL == reserve)
     196           0 :     return GNUNET_OK;
     197           8 :   GNUNET_free (reserve);
     198           8 :   return GNUNET_OK;
     199             : }
     200             : 
     201             : 
     202             : /**
     203             :  * Generate a dummy deposit for testing purposes
     204             :  * @param dki the denomination key used to sign the key
     205             :  */
     206             : struct TALER_EXCHANGEDB_Deposit *
     207           2 : PERF_TALER_EXCHANGEDB_deposit_init (const struct PERF_TALER_EXCHANGEDB_Coin *coin)
     208             : {
     209             :   struct TALER_EXCHANGEDB_Deposit *deposit;
     210             :   struct TALER_CoinSpendSignatureP csig;
     211             :   struct TALER_MerchantPublicKeyP merchant_pub;
     212             :   struct GNUNET_HashCode h_contract_terms;
     213             :   struct GNUNET_HashCode h_wire;
     214           2 :   const char wire[] = "{"
     215             :     "\"type\":\"SEPA\","
     216             :     "\"IBAN\":\"DE67830654080004822650\","
     217             :     "\"NAME\":\"GNUNET E.\","
     218             :     "\"BIC\":\"GENODEF1SRL\""
     219             :     "}";
     220             :   struct GNUNET_TIME_Absolute timestamp;
     221             :   struct GNUNET_TIME_Absolute refund_deadline;
     222             :   struct TALER_Amount amount_with_fee;
     223             :   struct TALER_Amount deposit_fee;
     224             : 
     225           2 :   GNUNET_assert (NULL !=
     226             :                  (deposit = GNUNET_malloc (sizeof (struct TALER_EXCHANGEDB_Deposit) + sizeof (wire))));
     227           2 :   GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
     228             :                                     &h_contract_terms);
     229           2 :   GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
     230             :                                     &h_wire);
     231             :   { //csig
     232             :     struct u32_presign
     233             :     {
     234             :       struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
     235             :       struct GNUNET_HashCode h_wire;
     236             :       struct GNUNET_HashCode h_contract_terms;
     237             :     } unsigned_data;
     238             : 
     239           2 :     unsigned_data.h_contract_terms = h_contract_terms;
     240           2 :     unsigned_data.h_wire = h_wire;
     241           2 :     unsigned_data.purpose.size = htonl (sizeof (struct u32_presign));
     242           2 :     unsigned_data.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST);
     243           2 :     GNUNET_assert (GNUNET_OK ==
     244             :                    GNUNET_CRYPTO_eddsa_sign (&coin->priv,
     245             :                                              &unsigned_data.purpose,
     246             :                                              &csig.eddsa_signature));
     247             :   }
     248             :   { //merchant_pub
     249             :     struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_prv;
     250             : 
     251           2 :     eddsa_prv = GNUNET_CRYPTO_eddsa_key_create ();
     252           2 :     GNUNET_assert(NULL != eddsa_prv);
     253           2 :     GNUNET_CRYPTO_eddsa_key_get_public (
     254             :       eddsa_prv,
     255             :       &merchant_pub.eddsa_pub);
     256           2 :     GNUNET_free (eddsa_prv);
     257             :   }
     258           2 :   timestamp = GNUNET_TIME_absolute_get ();
     259           2 :   refund_deadline = GNUNET_TIME_absolute_get ();
     260           2 :   GNUNET_assert (GNUNET_OK ==
     261             :                  TALER_string_to_amount (CURRENCY ":1.1",
     262             :                                          &amount_with_fee));
     263           2 :   GNUNET_assert (GNUNET_OK ==
     264             :                  TALER_string_to_amount (CURRENCY ":0.1",
     265             :                                          &deposit_fee));
     266             :   {
     267           2 :     deposit->coin.coin_pub = coin->public_info.coin_pub;
     268           2 :     deposit->coin.denom_pub.rsa_public_key = GNUNET_CRYPTO_rsa_public_key_dup (
     269           2 :       coin->public_info.denom_pub.rsa_public_key);
     270           2 :     GNUNET_assert (NULL != coin->public_info.denom_pub.rsa_public_key);
     271           2 :     deposit->coin.denom_sig.rsa_signature = GNUNET_CRYPTO_rsa_signature_dup (
     272           2 :       coin->public_info.denom_sig.rsa_signature);
     273           2 :     GNUNET_assert (NULL != coin->public_info.denom_sig.rsa_signature);
     274             :   }
     275           2 :   deposit->csig = csig;
     276           2 :   deposit->h_contract_terms = h_contract_terms;
     277           2 :   deposit->h_wire = h_wire;
     278           2 :   deposit->receiver_wire_account = json_loads (wire, 0, NULL);
     279           2 :   deposit->timestamp = timestamp;
     280           2 :   deposit->refund_deadline = refund_deadline;
     281           2 :   deposit->amount_with_fee = amount_with_fee;
     282           2 :   deposit->deposit_fee = deposit_fee;
     283           2 :   return deposit;
     284             : }
     285             : 
     286             : 
     287             : /**
     288             :  * Copies the given deposit
     289             :  * @param reserve the deposit copy
     290             :  * @return a copy of @a deposit; NULL if error
     291             :  */
     292             : struct TALER_EXCHANGEDB_Deposit *
     293           2 : PERF_TALER_EXCHANGEDB_deposit_copy (const struct TALER_EXCHANGEDB_Deposit *deposit)
     294             : {
     295             :   struct TALER_EXCHANGEDB_Deposit *copy;
     296             : 
     297           2 :   copy = GNUNET_new (struct TALER_EXCHANGEDB_Deposit);
     298           2 :   *copy = *deposit;
     299           2 :   json_incref (copy->receiver_wire_account);
     300           2 :   copy->coin.denom_pub.rsa_public_key =
     301           2 :     GNUNET_CRYPTO_rsa_public_key_dup (deposit->coin.denom_pub.rsa_public_key);
     302           2 :   copy->coin.denom_sig.rsa_signature =
     303           2 :     GNUNET_CRYPTO_rsa_signature_dup (deposit->coin.denom_sig.rsa_signature);
     304           2 :   return copy;
     305             : }
     306             : 
     307             : 
     308             : /**
     309             :  * Free memory of a deposit
     310             :  * @param deposit pointer to the structure to free
     311             :  */
     312             : int
     313           4 : PERF_TALER_EXCHANGEDB_deposit_free (struct TALER_EXCHANGEDB_Deposit *deposit)
     314             : {
     315           4 :   if (NULL == deposit)
     316           0 :     return GNUNET_OK;
     317           4 :   GNUNET_CRYPTO_rsa_public_key_free (deposit->coin.denom_pub.rsa_public_key);
     318           4 :   GNUNET_CRYPTO_rsa_signature_free (deposit->coin.denom_sig.rsa_signature);
     319           4 :   json_decref (deposit->receiver_wire_account);
     320           4 :   GNUNET_free (deposit);
     321           4 :   return GNUNET_OK;
     322             : }
     323             : 
     324             : 
     325             : /**
     326             :  * Generate a CollectableBlindcoin for testing purpuses
     327             :  * @param dki denomination key used to sign the coin
     328             :  * @param reserve reserve providing the money for the coin
     329             :  * @return a randomly generated CollectableBlindcoin
     330             :  */
     331             : struct PERF_TALER_EXCHANGEDB_Coin *
     332           2 : PERF_TALER_EXCHANGEDB_coin_init (
     333             :   const struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki,
     334             :   const struct PERF_TALER_EXCHANGEDB_Reserve *reserve)
     335             : {
     336             :   struct PERF_TALER_EXCHANGEDB_Coin *coin;
     337             :   struct GNUNET_CRYPTO_EddsaPrivateKey *priv;
     338             :   struct GNUNET_HashCode hc;
     339             : 
     340           2 :   coin = GNUNET_new (struct PERF_TALER_EXCHANGEDB_Coin);
     341           2 :   GNUNET_assert (NULL != coin);
     342             :   /* priv */
     343             : 
     344           2 :   priv = GNUNET_CRYPTO_eddsa_key_create();
     345           2 :   GNUNET_assert (NULL != priv);
     346           2 :   coin->priv = *priv;
     347           2 :   GNUNET_free (priv);
     348             : 
     349             :   /* public_info */
     350           2 :   GNUNET_CRYPTO_eddsa_key_get_public (&coin->priv,
     351             :                                       &coin->public_info.coin_pub.eddsa_pub);
     352           2 :   coin->public_info.denom_pub.rsa_public_key =
     353           2 :     GNUNET_CRYPTO_rsa_public_key_dup (dki->denom_pub.rsa_public_key);
     354           2 :   GNUNET_CRYPTO_hash (&coin->public_info.coin_pub,
     355             :                       sizeof (struct TALER_CoinSpendPublicKeyP),
     356             :                       &hc);
     357           2 :   coin->public_info.denom_sig.rsa_signature =
     358           2 :     GNUNET_CRYPTO_rsa_sign_fdh (dki->denom_priv.rsa_private_key,
     359             :                                 &hc);
     360           2 :   GNUNET_assert (NULL != coin->public_info.denom_pub.rsa_public_key);
     361           2 :   GNUNET_assert (NULL != coin->public_info.denom_sig.rsa_signature);
     362             : 
     363             :   /* blind */
     364           2 :   coin->blind.sig.rsa_signature =
     365           2 :     GNUNET_CRYPTO_rsa_signature_dup (coin->public_info.denom_sig.rsa_signature);
     366           2 :   coin->blind.denom_pub.rsa_public_key =
     367           2 :     GNUNET_CRYPTO_rsa_public_key_dup (dki->denom_pub.rsa_public_key);
     368           2 :   GNUNET_assert (NULL != coin->blind.sig.rsa_signature);
     369           2 :   GNUNET_assert (NULL != coin->blind.denom_pub.rsa_public_key);
     370           2 :   TALER_amount_ntoh (&coin->blind.amount_with_fee,
     371             :                      &dki->issue.properties.value);
     372           2 :   TALER_amount_ntoh (&coin->blind.withdraw_fee,
     373             :                      &dki->issue.properties.fee_withdraw);
     374           2 :   coin->blind.reserve_pub = reserve->reserve.pub;
     375           2 :   GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
     376             :                                     &coin->blind.h_coin_envelope);
     377             : 
     378           2 :   return coin;
     379             : }
     380             : 
     381             : 
     382             : /**
     383             :  * Copies the given coin
     384             :  *
     385             :  * @param coin the coin to copy
     386             :  * @return a copy of coin; NULL if error
     387             :  */
     388             : struct PERF_TALER_EXCHANGEDB_Coin *
     389           3 : PERF_TALER_EXCHANGEDB_coin_copy (const struct PERF_TALER_EXCHANGEDB_Coin *coin)
     390             : {
     391             :   struct PERF_TALER_EXCHANGEDB_Coin *copy;
     392             : 
     393           3 :   copy = GNUNET_new (struct PERF_TALER_EXCHANGEDB_Coin);
     394             :   /* priv */
     395           3 :   copy->priv = coin->priv;
     396             :   /* public_info */
     397           3 :   copy->public_info.coin_pub = coin->public_info.coin_pub;
     398           3 :   copy->public_info.denom_pub.rsa_public_key =
     399           3 :     GNUNET_CRYPTO_rsa_public_key_dup (coin->public_info.denom_pub.rsa_public_key);
     400           3 :   copy->public_info.denom_sig.rsa_signature =
     401           3 :     GNUNET_CRYPTO_rsa_signature_dup (coin->public_info.denom_sig.rsa_signature);
     402             : 
     403             :   /* blind */
     404           3 :   copy->blind.sig.rsa_signature =
     405           3 :     GNUNET_CRYPTO_rsa_signature_dup (coin->blind.sig.rsa_signature);
     406           3 :   copy->blind.denom_pub.rsa_public_key =
     407           3 :     GNUNET_CRYPTO_rsa_public_key_dup (coin->blind.denom_pub.rsa_public_key);
     408           3 :   copy->blind.amount_with_fee = coin->blind.amount_with_fee;
     409           3 :   copy->blind.withdraw_fee = coin->blind.withdraw_fee;
     410           3 :   copy->blind.reserve_pub = coin->blind.reserve_pub;
     411           3 :   copy->blind.h_coin_envelope = coin->blind.h_coin_envelope;
     412           3 :   copy->blind.reserve_sig = coin->blind.reserve_sig;
     413             : 
     414           3 :   return copy;
     415             : }
     416             : 
     417             : 
     418             : /**
     419             :  * Free memory of @a coin
     420             :  *
     421             :  * @param coin pointer to the structure to free
     422             :  */
     423             : int
     424           5 : PERF_TALER_EXCHANGEDB_coin_free (struct PERF_TALER_EXCHANGEDB_Coin *coin)
     425             : {
     426           5 :   if (NULL == coin)
     427           0 :     return GNUNET_OK;
     428           5 :   GNUNET_CRYPTO_rsa_public_key_free (coin->public_info.denom_pub.rsa_public_key);
     429           5 :   GNUNET_CRYPTO_rsa_signature_free (coin->public_info.denom_sig.rsa_signature);
     430           5 :   GNUNET_CRYPTO_rsa_signature_free (coin->blind.sig.rsa_signature);
     431           5 :   GNUNET_CRYPTO_rsa_public_key_free (coin->blind.denom_pub.rsa_public_key);
     432           5 :   GNUNET_free (coin);
     433           5 :   return GNUNET_OK;
     434             : }
     435             : 
     436             : 
     437             : /**
     438             :  * @return a randomly generated refresh session
     439             :  */
     440             : struct TALER_EXCHANGEDB_RefreshSession *
     441           0 : PERF_TALER_EXCHANGEDB_refresh_session_init ()
     442             : {
     443             :   struct TALER_EXCHANGEDB_RefreshSession *refresh_session;
     444             : 
     445           0 :   GNUNET_assert (NULL !=
     446             :                  (refresh_session = GNUNET_new (struct TALER_EXCHANGEDB_RefreshSession)));
     447           0 :   refresh_session->noreveal_index = 1;
     448           0 :   refresh_session->num_newcoins = 1;
     449             : 
     450           0 :   return refresh_session;
     451             : }
     452             : 
     453             : 
     454             : /**
     455             :  * @return #GNUNET_OK if the copy was successful, #GNUNET_SYSERR if it wasn't
     456             :  */
     457             : int
     458           0 : PERF_TALER_EXCHANGEDB_refresh_session_copy (struct TALER_EXCHANGEDB_RefreshSession *session,
     459             :                                             struct TALER_EXCHANGEDB_RefreshSession *copy)
     460             : {
     461           0 :   *copy = *session;
     462           0 :   return GNUNET_OK;
     463             : }
     464             : 
     465             : 
     466             : /**
     467             :  * Free a refresh session
     468             :  */
     469             : int
     470           0 : PERF_TALER_EXCHANGEDB_refresh_session_free (struct TALER_EXCHANGEDB_RefreshSession *refresh_session)
     471             : {
     472           0 :   if (NULL == refresh_session)
     473           0 :     return GNUNET_OK;
     474           0 :   GNUNET_free (refresh_session);
     475           0 :   return GNUNET_OK;
     476             : }
     477             : 
     478             : 
     479             : /**
     480             :  * Create a melt operation
     481             :  *
     482             :  * @param session the refresh session
     483             :  * @param dki the denomination the melted coin uses
     484             :  * @return a pointer to a #TALER_EXCHANGEDB_RefreshMelt
     485             :  */
     486             : struct TALER_EXCHANGEDB_RefreshMelt *
     487           0 : PERF_TALER_EXCHANGEDB_refresh_melt_init (struct GNUNET_HashCode *session,
     488             :                                          struct PERF_TALER_EXCHANGEDB_Coin *coin)
     489             : {
     490             :   struct TALER_EXCHANGEDB_RefreshMelt *melt;
     491             :   struct TALER_CoinSpendSignatureP coin_sig;
     492             :   struct TALER_Amount amount;
     493             :   struct TALER_Amount amount_with_fee;
     494             : 
     495             :   {
     496             :     struct
     497             :     {
     498             :       struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
     499             :       struct GNUNET_HashCode session;
     500             :     } to_sign;
     501             : 
     502           0 :     to_sign.purpose.purpose = GNUNET_SIGNATURE_PURPOSE_TEST;
     503           0 :     to_sign.purpose.size = htonl (sizeof (to_sign));
     504           0 :     to_sign.session = *session;
     505           0 :     GNUNET_CRYPTO_eddsa_sign (&coin->priv,
     506             :                               &to_sign.purpose,
     507             :                               &coin_sig.eddsa_signature);
     508             :   }
     509           0 :   GNUNET_assert (GNUNET_OK ==
     510             :                  TALER_string_to_amount (CURRENCY ":1.1",
     511             :                                          &amount));
     512           0 :   GNUNET_assert (GNUNET_OK ==
     513             :                  TALER_string_to_amount (CURRENCY ":0.1",
     514             :                                          &amount_with_fee));
     515           0 :   melt = GNUNET_new (struct TALER_EXCHANGEDB_RefreshMelt);
     516           0 :   melt->coin.coin_pub = coin->public_info.coin_pub;
     517           0 :   melt->coin.denom_sig.rsa_signature =
     518           0 :     GNUNET_CRYPTO_rsa_signature_dup (coin->public_info.denom_sig.rsa_signature);
     519           0 :   melt->coin.denom_pub.rsa_public_key =
     520           0 :     GNUNET_CRYPTO_rsa_public_key_dup (coin->public_info.denom_pub.rsa_public_key);
     521           0 :   GNUNET_assert (NULL != melt->coin.denom_pub.rsa_public_key);
     522           0 :   GNUNET_assert (NULL != melt->coin.denom_sig.rsa_signature);
     523           0 :   melt->coin_sig = coin_sig;
     524           0 :   melt->session_hash = *session;
     525           0 :   melt->amount_with_fee = amount;
     526           0 :   melt->melt_fee = amount_with_fee;
     527           0 :   return melt;
     528             : }
     529             : 
     530             : 
     531             : /**
     532             :  * Copies the internals of a #TALER_EXCHANGEDB_RefreshMelt
     533             :  *
     534             :  * @param melt the refresh melt to copy
     535             :  * @return an copy of @ melt
     536             :  */
     537             : struct TALER_EXCHANGEDB_RefreshMelt *
     538           0 : PERF_TALER_EXCHANGEDB_refresh_melt_copy (const struct TALER_EXCHANGEDB_RefreshMelt *melt)
     539             : {
     540             :   struct TALER_EXCHANGEDB_RefreshMelt *copy;
     541             : 
     542           0 :   copy = GNUNET_new (struct TALER_EXCHANGEDB_RefreshMelt);
     543           0 :   *copy = *melt;
     544           0 :   copy->coin.denom_sig.rsa_signature =
     545           0 :     GNUNET_CRYPTO_rsa_signature_dup (melt->coin.denom_sig.rsa_signature);
     546           0 :   GNUNET_assert (NULL != copy->coin.denom_sig.rsa_signature);
     547             : 
     548           0 :   return copy;
     549             : }
     550             : 
     551             : 
     552             : /**
     553             :  * Free the internal memory of a #TALER_EXCHANGEDB_RefreshMelt
     554             :  *
     555             :  * @param melt the #TALER_EXCHANGEDB_RefreshMelt to free
     556             :  * @return #GNUNET_OK if the operation was successful, #GNUNET_SYSERROR
     557             :  */
     558             : int
     559           0 : PERF_TALER_EXCHANGEDB_refresh_melt_free (struct TALER_EXCHANGEDB_RefreshMelt *melt)
     560             : {
     561           0 :   GNUNET_CRYPTO_rsa_signature_free (melt->coin.denom_sig.rsa_signature);
     562           0 :   GNUNET_free (melt);
     563           0 :   return GNUNET_OK;
     564             : }
     565             : 
     566             : 
     567             : /**
     568             :  * Create a #TALER_EXCHANGEDB_RefreshCommitCoin
     569             :  */
     570             : struct TALER_EXCHANGEDB_RefreshCommitCoin *
     571           0 : PERF_TALER_EXCHANGEDB_refresh_commit_coin_init ()
     572             : {
     573             :   struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coin;
     574             : 
     575           0 :   commit_coin = GNUNET_new (struct TALER_EXCHANGEDB_RefreshCommitCoin);
     576           0 :   commit_coin->coin_ev = "coin_ev";
     577           0 :   commit_coin->coin_ev_size = 8;
     578           0 :   return commit_coin;
     579             : }
     580             : 
     581             : 
     582             : /**
     583             :  * Copies a #TALER_EXCHANGEDB_RefreshCommitCoin
     584             :  *
     585             :  * @param commit_coin the commit to copy
     586             :  * @return a copy of @a commit_coin
     587             :  */
     588             : struct TALER_EXCHANGEDB_RefreshCommitCoin *
     589           0 : PERF_TALER_EXCHANGEDB_refresh_commit_coin_copy (struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coin)
     590             : {
     591             :   struct TALER_EXCHANGEDB_RefreshCommitCoin *copy;
     592             : 
     593           0 :   copy = GNUNET_new (struct TALER_EXCHANGEDB_RefreshCommitCoin);
     594           0 :   *copy = *commit_coin;
     595           0 :   return copy;
     596             : }
     597             : 
     598             : 
     599             : /**
     600             :  * Free a #TALER_EXCHANGEDB_RefreshCommitCoin
     601             :  *
     602             :  * @param commit_coin the coin to free
     603             :  */
     604             : void
     605           0 : PERF_TALER_EXCHANGEDB_refresh_commit_coin_free (struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coin)
     606             : {
     607           0 :   GNUNET_free (commit_coin);
     608           0 : }

Generated by: LCOV version 1.13