gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-exchange] 08/130: -resovling more FTBFS issues


From: gnunet
Subject: [taler-exchange] 08/130: -resovling more FTBFS issues
Date: Wed, 17 Nov 2021 12:24:16 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository exchange.

commit 868a4ce76d543aaf0de7a12dbbddd3fd1d4571b6
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat Oct 23 07:11:23 2021 +0200

    -resovling more FTBFS issues
---
 src/exchangedb/plugin_exchangedb_common.c   |  10 +-
 src/exchangedb/plugin_exchangedb_postgres.c |  70 ++++----
 src/include/taler_crypto_lib.h              |  27 +++
 src/include/taler_exchangedb_plugin.h       |   2 +-
 src/include/taler_pq_lib.h                  |  57 +++++-
 src/pq/pq_query_helper.c                    | 262 +++++++++++++++++++++------
 src/pq/pq_result_helper.c                   | 270 +++++++++++++++++++++++-----
 src/util/denom.c                            |  57 ++++++
 8 files changed, 614 insertions(+), 141 deletions(-)

diff --git a/src/exchangedb/plugin_exchangedb_common.c 
b/src/exchangedb/plugin_exchangedb_common.c
index fb697dae..8f85e3ea 100644
--- a/src/exchangedb/plugin_exchangedb_common.c
+++ b/src/exchangedb/plugin_exchangedb_common.c
@@ -49,7 +49,7 @@ common_free_reserve_history (void *cls,
         struct TALER_EXCHANGEDB_CollectableBlindcoin *cbc;
 
         cbc = rh->details.withdraw;
-        GNUNET_CRYPTO_rsa_signature_free (cbc->sig.rsa_signature);
+        TALER_denom_sig_free (&cbc->sig);
         GNUNET_free (cbc);
         break;
       }
@@ -58,7 +58,7 @@ common_free_reserve_history (void *cls,
         struct TALER_EXCHANGEDB_Recoup *recoup;
 
         recoup = rh->details.recoup;
-        GNUNET_CRYPTO_rsa_signature_free 
(recoup->coin.denom_sig.rsa_signature);
+        TALER_denom_sig_free (&recoup->coin.denom_sig);
         GNUNET_free (recoup);
         break;
       }
@@ -116,8 +116,7 @@ common_free_coin_transaction_list (void *cls,
         struct TALER_EXCHANGEDB_RecoupRefreshListEntry *rr;
 
         rr = tl->details.old_coin_recoup;
-        if (NULL != rr->coin.denom_sig.rsa_signature)
-          GNUNET_CRYPTO_rsa_signature_free (rr->coin.denom_sig.rsa_signature);
+        TALER_denom_sig_free (&rr->coin.denom_sig);
         GNUNET_free (rr);
         break;
       }
@@ -132,8 +131,7 @@ common_free_coin_transaction_list (void *cls,
         struct TALER_EXCHANGEDB_RecoupRefreshListEntry *rr;
 
         rr = tl->details.recoup_refresh;
-        if (NULL != rr->coin.denom_sig.rsa_signature)
-          GNUNET_CRYPTO_rsa_signature_free (rr->coin.denom_sig.rsa_signature);
+        TALER_denom_sig_free (&rr->coin.denom_sig);
         GNUNET_free (rr);
         break;
       }
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c 
b/src/exchangedb/plugin_exchangedb_postgres.c
index 4b3ae19d..ff85f4a2 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -2917,7 +2917,7 @@ postgres_insert_denomination_info (
 static enum GNUNET_DB_QueryStatus
 postgres_get_denomination_info (
   void *cls,
-  const struct GNUNET_HashCode *denom_pub_hash,
+  const struct TALER_DenominationHash *denom_pub_hash,
   struct TALER_EXCHANGEDB_DenominationKeyInformationP *issue)
 {
   struct PostgresClosure *pg = cls;
@@ -3135,7 +3135,7 @@ dominations_cb_helper (void *cls,
     struct TALER_EXCHANGEDB_DenominationKeyMetaData meta;
     struct TALER_DenominationPublicKey denom_pub;
     struct TALER_MasterSignatureP master_sig;
-    struct GNUNET_HashCode h_denom_pub;
+    struct TALER_DenominationHash h_denom_pub;
     uint8_t revoked;
     struct GNUNET_PQ_ResultSpec rs[] = {
       GNUNET_PQ_result_spec_auto_from_type ("master_sig",
@@ -3454,7 +3454,7 @@ auditor_denoms_cb_helper (void *cls,
   for (unsigned int i = 0; i<num_results; i++)
   {
     struct TALER_AuditorPublicKeyP auditor_pub;
-    struct GNUNET_HashCode h_denom_pub;
+    struct TALER_DenominationHash h_denom_pub;
     struct TALER_AuditorSignatureP auditor_sig;
     struct GNUNET_PQ_ResultSpec rs[] = {
       GNUNET_PQ_result_spec_auto_from_type ("auditor_pub",
@@ -3646,7 +3646,7 @@ postgres_get_kyc_status (void *cls,
 static enum GNUNET_DB_QueryStatus
 postgres_select_kyc_status (void *cls,
                             uint64_t payment_target_uuid,
-                            struct GNUNET_HashCode *h_payto,
+                            struct TALER_PaytoHash *h_payto,
                             struct TALER_EXCHANGEDB_KycStatus *kyc)
 {
 #if FIXME_DD23
@@ -4114,7 +4114,7 @@ postgres_get_latest_reserve_in_reference (
 static enum GNUNET_DB_QueryStatus
 postgres_get_withdraw_info (
   void *cls,
-  const struct GNUNET_HashCode *h_blind,
+  const struct TALER_BlindedCoinHash *h_blind,
   struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable)
 {
   struct PostgresClosure *pg = cls;
@@ -4858,8 +4858,9 @@ static enum GNUNET_DB_QueryStatus
 postgres_test_deposit_done (void *cls,
                             const struct TALER_CoinSpendPublicKeyP *coin_pub,
                             const struct TALER_MerchantPublicKeyP 
*merchant_pub,
-                            const struct GNUNET_HashCode *h_contract_terms,
-                            const struct GNUNET_HashCode *h_wire)
+                            const struct
+                            TALER_PrivateContractHash *h_contract_terms,
+                            const struct TALER_MerchantWireHash *h_wire)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
@@ -4945,7 +4946,7 @@ postgres_get_ready_deposit (void *cls,
   };
   struct TALER_Amount amount_with_fee;
   struct TALER_Amount deposit_fee;
-  struct GNUNET_HashCode h_contract_terms;
+  struct TALER_PrivateContractHash h_contract_terms;
   struct TALER_MerchantPublicKeyP merchant_pub;
   struct TALER_CoinSpendPublicKeyP coin_pub;
   uint64_t serial_id;
@@ -5066,7 +5067,7 @@ match_deposit_cb (void *cls,
   {
     struct TALER_Amount amount_with_fee;
     struct TALER_Amount deposit_fee;
-    struct GNUNET_HashCode h_contract_terms;
+    struct TALER_PrivateContractHash h_contract_terms;
     struct TALER_CoinSpendPublicKeyP coin_pub;
     uint64_t serial_id;
     enum GNUNET_DB_QueryStatus qs;
@@ -5122,7 +5123,7 @@ match_deposit_cb (void *cls,
 static enum GNUNET_DB_QueryStatus
 postgres_iterate_matching_deposits (
   void *cls,
-  const struct GNUNET_HashCode *h_wire,
+  const struct TALER_MerchantWireHash *h_wire,
   const struct TALER_MerchantPublicKeyP *merchant_pub,
   TALER_EXCHANGEDB_MatchingDepositIterator deposit_cb,
   void *deposit_cb_cls,
@@ -5209,7 +5210,7 @@ static enum GNUNET_DB_QueryStatus
 postgres_get_coin_denomination (
   void *cls,
   const struct TALER_CoinSpendPublicKeyP *coin_pub,
-  struct GNUNET_HashCode *denom_hash)
+  struct TALER_DenominationHash *denom_hash)
 {
   struct PostgresClosure *pg = cls;
   struct GNUNET_PQ_QueryParam params[] = {
@@ -5271,7 +5272,7 @@ insert_known_coin (void *cls,
  */
 static long long
 postgres_count_known_coins (void *cls,
-                            const struct GNUNET_HashCode *denom_pub_hash)
+                            const struct TALER_DenominationHash 
*denom_pub_hash)
 {
   struct PostgresClosure *pg = cls;
   uint64_t count;
@@ -5309,7 +5310,7 @@ postgres_ensure_coin_known (void *cls,
 {
   struct PostgresClosure *pg = cls;
   enum GNUNET_DB_QueryStatus qs;
-  struct GNUNET_HashCode denom_pub_hash;
+  struct TALER_DenominationHash denom_pub_hash;
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (&coin->coin_pub),
     GNUNET_PQ_query_param_end
@@ -5557,7 +5558,7 @@ postgres_select_refunds_by_coin (
   void *cls,
   const struct TALER_CoinSpendPublicKeyP *coin_pub,
   const struct TALER_MerchantPublicKeyP *merchant_pub,
-  const struct GNUNET_HashCode *h_contract,
+  const struct TALER_PrivateContractHash *h_contract,
   TALER_EXCHANGEDB_RefundCoinCallback cb,
   void *cb_cls)
 {
@@ -5731,8 +5732,8 @@ postgres_insert_refresh_reveal (
   for (uint32_t i = 0; i<num_rrcs; i++)
   {
     const struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrc = &rrcs[i];
-    struct GNUNET_HashCode denom_pub_hash;
-    struct GNUNET_HashCode h_coin_ev;
+    struct TALER_DenominationHash denom_pub_hash;
+    struct TALER_BlindedCoinHash h_coin_ev;
     struct GNUNET_PQ_QueryParam params[] = {
       GNUNET_PQ_query_param_auto_from_type (rc),
       GNUNET_PQ_query_param_uint32 (&i),
@@ -6752,8 +6753,8 @@ handle_wt_result (void *cls,
   for (unsigned int i = 0; i<num_results; i++)
   {
     uint64_t rowid;
-    struct GNUNET_HashCode h_contract_terms;
-    struct GNUNET_HashCode h_wire;
+    struct TALER_PrivateContractHash h_contract_terms;
+    struct TALER_MerchantWireHash h_wire;
     struct TALER_CoinSpendPublicKeyP coin_pub;
     struct TALER_MerchantPublicKeyP merchant_pub;
     struct GNUNET_TIME_Absolute exec_time;
@@ -6866,8 +6867,8 @@ postgres_lookup_wire_transfer (
 static enum GNUNET_DB_QueryStatus
 postgres_lookup_transfer_by_deposit (
   void *cls,
-  const struct GNUNET_HashCode *h_contract_terms,
-  const struct GNUNET_HashCode *h_wire,
+  const struct TALER_PrivateContractHash *h_contract_terms,
+  const struct TALER_MerchantWireHash *h_wire,
   const struct TALER_CoinSpendPublicKeyP *coin_pub,
   const struct TALER_MerchantPublicKeyP *merchant_pub,
   bool *pending,
@@ -8315,7 +8316,7 @@ reserves_out_serial_helper_cb (void *cls,
 
   for (unsigned int i = 0; i<num_results; i++)
   {
-    struct GNUNET_HashCode h_blind_ev;
+    struct TALER_BlindedCoinHash h_blind_ev;
     struct TALER_DenominationPublicKey denom_pub;
     struct TALER_ReservePublicKeyP reserve_pub;
     struct TALER_ReserveSignatureP reserve_sig;
@@ -8632,7 +8633,7 @@ recoup_serial_helper_cb (void *cls,
     struct TALER_DenominationBlindingKeyP coin_blind;
     struct TALER_Amount amount;
     struct TALER_DenominationPublicKey denom_pub;
-    struct GNUNET_HashCode h_blind_ev;
+    struct TALER_BlindedCoinHash h_blind_ev;
     struct GNUNET_TIME_Absolute timestamp;
     struct GNUNET_PQ_ResultSpec rs[] = {
       GNUNET_PQ_result_spec_uint64 ("recoup_uuid",
@@ -8779,9 +8780,9 @@ recoup_refresh_serial_helper_cb (void *cls,
     struct TALER_CoinSpendSignatureP coin_sig;
     struct TALER_DenominationBlindingKeyP coin_blind;
     struct TALER_DenominationPublicKey denom_pub;
-    struct GNUNET_HashCode old_denom_pub_hash;
+    struct TALER_DenominationHash old_denom_pub_hash;
     struct TALER_Amount amount;
-    struct GNUNET_HashCode h_blind_ev;
+    struct TALER_BlindedCoinHash h_blind_ev;
     struct GNUNET_TIME_Absolute timestamp;
     struct GNUNET_PQ_ResultSpec rs[] = {
       GNUNET_PQ_result_spec_uint64 ("recoup_refresh_uuid",
@@ -9040,7 +9041,7 @@ postgres_insert_recoup_request (
   const struct TALER_CoinSpendSignatureP *coin_sig,
   const struct TALER_DenominationBlindingKeyP *coin_blind,
   const struct TALER_Amount *amount,
-  const struct GNUNET_HashCode *h_blind_ev,
+  const struct TALER_BlindedCoinHash *h_blind_ev,
   struct GNUNET_TIME_Absolute timestamp)
 {
   struct PostgresClosure *pg = cls;
@@ -9132,7 +9133,7 @@ postgres_insert_recoup_refresh_request (
   const struct TALER_CoinSpendSignatureP *coin_sig,
   const struct TALER_DenominationBlindingKeyP *coin_blind,
   const struct TALER_Amount *amount,
-  const struct GNUNET_HashCode *h_blind_ev,
+  const struct TALER_BlindedCoinHash *h_blind_ev,
   struct GNUNET_TIME_Absolute timestamp)
 {
   struct PostgresClosure *pg = cls;
@@ -9174,7 +9175,7 @@ postgres_insert_recoup_refresh_request (
  */
 static enum GNUNET_DB_QueryStatus
 postgres_get_reserve_by_h_blind (void *cls,
-                                 const struct GNUNET_HashCode *h_blind_ev,
+                                 const struct TALER_BlindedCoinHash 
*h_blind_ev,
                                  struct TALER_ReservePublicKeyP *reserve_pub)
 {
   struct PostgresClosure *pg = cls;
@@ -9206,7 +9207,8 @@ postgres_get_reserve_by_h_blind (void *cls,
  */
 static enum GNUNET_DB_QueryStatus
 postgres_get_old_coin_by_h_blind (void *cls,
-                                  const struct GNUNET_HashCode *h_blind_ev,
+                                  const struct
+                                  TALER_BlindedCoinHash *h_blind_ev,
                                   struct TALER_CoinSpendPublicKeyP 
*old_coin_pub)
 {
   struct PostgresClosure *pg = cls;
@@ -9239,7 +9241,7 @@ postgres_get_old_coin_by_h_blind (void *cls,
 static enum GNUNET_DB_QueryStatus
 postgres_insert_denomination_revocation (
   void *cls,
-  const struct GNUNET_HashCode *denom_pub_hash,
+  const struct TALER_DenominationHash *denom_pub_hash,
   const struct TALER_MasterSignatureP *master_sig)
 {
   struct PostgresClosure *pg = cls;
@@ -9268,7 +9270,7 @@ postgres_insert_denomination_revocation (
 static enum GNUNET_DB_QueryStatus
 postgres_get_denomination_revocation (
   void *cls,
-  const struct GNUNET_HashCode *denom_pub_hash,
+  const struct TALER_DenominationHash *denom_pub_hash,
   struct TALER_MasterSignatureP *master_sig,
   uint64_t *rowid)
 {
@@ -9957,7 +9959,7 @@ postgres_lookup_signkey_revocation (
 static enum GNUNET_DB_QueryStatus
 postgres_lookup_denomination_key (
   void *cls,
-  const struct GNUNET_HashCode *h_denom_pub,
+  const struct TALER_DenominationHash *h_denom_pub,
   struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta)
 {
   struct PostgresClosure *pg = cls;
@@ -10008,7 +10010,7 @@ postgres_lookup_denomination_key (
 static enum GNUNET_DB_QueryStatus
 postgres_add_denomination_key (
   void *cls,
-  const struct GNUNET_HashCode *h_denom_pub,
+  const struct TALER_DenominationHash *h_denom_pub,
   const struct TALER_DenominationPublicKey *denom_pub,
   const struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta,
   const struct TALER_MasterSignatureP *master_sig)
@@ -10129,7 +10131,7 @@ postgres_lookup_signing_key (
 static enum GNUNET_DB_QueryStatus
 postgres_insert_auditor_denom_sig (
   void *cls,
-  const struct GNUNET_HashCode *h_denom_pub,
+  const struct TALER_DenominationHash *h_denom_pub,
   const struct TALER_AuditorPublicKeyP *auditor_pub,
   const struct TALER_AuditorSignatureP *auditor_sig)
 {
@@ -10159,7 +10161,7 @@ postgres_insert_auditor_denom_sig (
 static enum GNUNET_DB_QueryStatus
 postgres_select_auditor_denom_sig (
   void *cls,
-  const struct GNUNET_HashCode *h_denom_pub,
+  const struct TALER_DenominationHash *h_denom_pub,
   const struct TALER_AuditorPublicKeyP *auditor_pub,
   struct TALER_AuditorSignatureP *auditor_sig)
 {
diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h
index 185c29a1..561f2bd0 100644
--- a/src/include/taler_crypto_lib.h
+++ b/src/include/taler_crypto_lib.h
@@ -623,6 +623,33 @@ struct TALER_TrackTransferDetails
 };
 
 
+/**
+ * Free internals of @a denom_pub, but not @a denom_pub itself.
+ *
+ * @param[in] denom_pub key to free
+ */
+void
+TALER_denom_pub_free (struct TALER_DenominationPublicKey *denom_pub);
+
+
+/**
+ * Free internals of @a denom_priv, but not @a denom_priv itself.
+ *
+ * @param[in] denom_priv key to free
+ */
+void
+TALER_denom_priv_free (struct TALER_DenominationPrivateKey *denom_priv);
+
+
+/**
+ * Free internals of @a denom_sig, but not @a denom_sig itself.
+ *
+ * @param[in] denom_sig signature to free
+ */
+void
+TALER_denom_sig_free (struct TALER_DenominationSignature *denom_sig);
+
+
 /**
  * Compute the hash of the given @a denom_pub.
  *
diff --git a/src/include/taler_exchangedb_plugin.h 
b/src/include/taler_exchangedb_plugin.h
index 83040dbe..8b01ee65 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -1969,7 +1969,7 @@ typedef enum GNUNET_GenericReturnValue
   struct GNUNET_TIME_Absolute timestamp,
   const struct TALER_Amount *amount,
   const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
-  const struct TLAER_DenominationHash *old_denom_pub_hash,
+  const struct TALER_DenominationHash *old_denom_pub_hash,
   const struct TALER_CoinPublicInfo *coin,
   const struct TALER_DenominationPublicKey *denom_pub,
   const struct TALER_CoinSpendSignatureP *coin_sig,
diff --git a/src/include/taler_pq_lib.h b/src/include/taler_pq_lib.h
index 4545b6d5..07057722 100644
--- a/src/include/taler_pq_lib.h
+++ b/src/include/taler_pq_lib.h
@@ -41,10 +41,10 @@ TALER_PQ_query_param_amount_nbo (const struct 
TALER_AmountNBO *x);
 
 
 /**
- * Generate query parameter for a currency, consisting of the three
- * components "value", "fraction" and "currency" in this order. The
- * types must be a 64-bit integer, 32-bit integer and a
- * #TALER_CURRENCY_LEN-sized BLOB/VARCHAR respectively.
+ * Generate query parameter for an amount, consisting of the two
+ * components "value" and "fraction" in this order. The
+ * types must be a 64-bit integer and a 32-bit integer
+ * respectively. The currency is dropped.
  *
  * @param x pointer to the query parameter to pass
  */
@@ -52,6 +52,31 @@ struct GNUNET_PQ_QueryParam
 TALER_PQ_query_param_amount (const struct TALER_Amount *x);
 
 
+/**
+ * Generate query parameter for a denomination public
+ * key. Internally, the various attributes of the
+ * public key will be serialized into on variable-size
+ * BLOB.
+ *
+ * @param x pointer to the query parameter to pass
+ */
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_denom_pub (
+  const struct TALER_DenominationPublicKey *denom_pub);
+
+
+/**
+ * Generate query parameter for a denomination signature.  Internally, the
+ * various attributes of the signature will be serialized into on
+ * variable-size BLOB.
+ *
+ * @param x pointer to the query parameter to pass
+ */
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_denom_sig (
+  const struct TALER_DenominationSignature *denom_sig);
+
+
 /**
  * Generate query parameter for a JSON object (stored as a string
  * in the DB).  Note that @a x must really be a JSON object or array,
@@ -119,6 +144,30 @@ TALER_PQ_result_spec_amount (const char *name,
                              struct TALER_Amount *amount);
 
 
+/**
+ * Denomination public key expected.
+ *
+ * @param name name of the field in the table
+ * @param[out] denom_pub where to store the public key
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_denom_pub (const char *name,
+                                struct TALER_DenominationPublicKey *denom_pub);
+
+
+/**
+ * Denomination signature expected.
+ *
+ * @param name name of the field in the table
+ * @param[out] denom_sig where to store the denomination signature
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_denom_sig (const char *name,
+                                struct TALER_DenominationSignature *denom_sig);
+
+
 /**
  * json_t expected.
  *
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index f558cbcc..3f51ddbe 100644
--- a/src/pq/pq_query_helper.c
+++ b/src/pq/pq_query_helper.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  Copyright (C) 2014, 2015, 2016 Taler Systems SA
+  Copyright (C) 2014, 2015, 2016, 2021 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
@@ -70,20 +70,16 @@ qconv_amount_nbo (void *cls,
 }
 
 
-/**
- * Generate query parameter for a currency, consisting of the three
- * components "value", "fraction" and "currency" in this order. The
- * types must be a 64-bit integer, 32-bit integer and a
- * #TALER_CURRENCY_LEN-sized BLOB/VARCHAR respectively.
- *
- * @param x pointer to the query parameter to pass
- * @return array entry for the query parameters to use
- */
 struct GNUNET_PQ_QueryParam
 TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x)
 {
-  struct GNUNET_PQ_QueryParam res =
-  { &qconv_amount_nbo, NULL, x, sizeof (*x), 2 };
+  struct GNUNET_PQ_QueryParam res = {
+    .conv = &qconv_amount_nbo,
+    .data = x,
+    .size = sizeof (*x),
+    .num_params = 2
+  };
+
   return res;
 }
 
@@ -138,20 +134,193 @@ qconv_amount (void *cls,
 }
 
 
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_amount (const struct TALER_Amount *x)
+{
+  struct GNUNET_PQ_QueryParam res = {
+    .conv = &qconv_amount,
+    .data = x,
+    .size = sizeof (*x),
+    .num_params = 2
+  };
+
+  return res;
+}
+
+
 /**
- * Generate query parameter for a currency, consisting of the three
- * components "value", "fraction" and "currency" in this order. The
- * types must be a 64-bit integer, 32-bit integer and a
- * #TALER_CURRENCY_LEN-sized BLOB/VARCHAR respectively.
+ * Function called to convert input argument into SQL parameters.
  *
- * @param x pointer to the query parameter to pass
- * @return array entry for the query parameters to use
+ * @param cls closure
+ * @param data pointer to input argument
+ * @param data_len number of bytes in @a data (if applicable)
+ * @param[out] param_values SQL data to set
+ * @param[out] param_lengths SQL length data to set
+ * @param[out] param_formats SQL format data to set
+ * @param param_length number of entries available in the @a param_values, @a 
param_lengths and @a param_formats arrays
+ * @param[out] scratch buffer for dynamic allocations (to be done via 
#GNUNET_malloc()
+ * @param scratch_length number of entries left in @a scratch
+ * @return -1 on error, number of offsets used in @a scratch otherwise
  */
+static int
+qconv_denom_pub (void *cls,
+                 const void *data,
+                 size_t data_len,
+                 void *param_values[],
+                 int param_lengths[],
+                 int param_formats[],
+                 unsigned int param_length,
+                 void *scratch[],
+                 unsigned int scratch_length)
+{
+  const struct TALER_DenominationPublicKey *denom_pub = data;
+  size_t tlen;
+  size_t len;
+  uint32_t be[2];
+  char *buf;
+  void *tbuf;
+
+  (void) cls;
+  GNUNET_assert (1 == param_length);
+  GNUNET_assert (scratch_length > 0);
+  GNUNET_break (NULL == cls);
+  be[0] = htonl ((uint32_t) denom_pub->cipher);
+  be[1] = htonl (denom_pub->age_mask);
+  switch (denom_pub->cipher)
+  {
+  case TALER_DENOMINATION_RSA:
+    tlen = GNUNET_CRYPTO_rsa_public_key_encode (
+      denom_pub->details.rsa_public_key,
+      &tbuf);
+    break;
+  // TODO: add case for Clause-Schnorr
+  default:
+    GNUNET_assert (0);
+  }
+  len = tlen + sizeof (be);
+  buf = GNUNET_malloc (len);
+  memcpy (buf,
+          be,
+          sizeof (be));
+  switch (denom_pub->cipher)
+  {
+  case TALER_DENOMINATION_RSA:
+    memcpy (&buf[sizeof (be)],
+            tbuf,
+            tlen);
+    GNUNET_free (tbuf);
+    break;
+  // TODO: add case for Clause-Schnorr
+  default:
+    GNUNET_assert (0);
+  }
+
+  scratch[0] = buf;
+  param_values[0] = (void *) buf;
+  param_lengths[0] = len;
+  param_formats[0] = 1;
+  return 1;
+}
+
+
 struct GNUNET_PQ_QueryParam
-TALER_PQ_query_param_amount (const struct TALER_Amount *x)
+TALER_PQ_query_param_denom_pub (
+  const struct TALER_DenominationPublicKey *denom_pub)
+{
+  struct GNUNET_PQ_QueryParam res = {
+    .conv = &qconv_denom_pub,
+    .data = denom_pub,
+    .num_params = 1
+  };
+
+  return res;
+}
+
+
+/**
+ * Function called to convert input argument into SQL parameters.
+ *
+ * @param cls closure
+ * @param data pointer to input argument
+ * @param data_len number of bytes in @a data (if applicable)
+ * @param[out] param_values SQL data to set
+ * @param[out] param_lengths SQL length data to set
+ * @param[out] param_formats SQL format data to set
+ * @param param_length number of entries available in the @a param_values, @a 
param_lengths and @a param_formats arrays
+ * @param[out] scratch buffer for dynamic allocations (to be done via 
#GNUNET_malloc()
+ * @param scratch_length number of entries left in @a scratch
+ * @return -1 on error, number of offsets used in @a scratch otherwise
+ */
+static int
+qconv_denom_sig (void *cls,
+                 const void *data,
+                 size_t data_len,
+                 void *param_values[],
+                 int param_lengths[],
+                 int param_formats[],
+                 unsigned int param_length,
+                 void *scratch[],
+                 unsigned int scratch_length)
+{
+  const struct TALER_DenominationSignature *denom_sig = data;
+  size_t tlen;
+  size_t len;
+  uint32_t be;
+  char *buf;
+  void *tbuf;
+
+  (void) cls;
+  GNUNET_assert (1 == param_length);
+  GNUNET_assert (scratch_length > 0);
+  GNUNET_break (NULL == cls);
+  be = htonl ((uint32_t) denom_sig->cipher);
+  switch (denom_sig->cipher)
+  {
+  case TALER_DENOMINATION_RSA:
+    tlen = GNUNET_CRYPTO_rsa_signature_encode (
+      denom_sig->details.rsa_signature,
+      &tbuf);
+    break;
+  // TODO: add case for Clause-Schnorr
+  default:
+    GNUNET_assert (0);
+  }
+  len = tlen + sizeof (be);
+  buf = GNUNET_malloc (len);
+  memcpy (buf,
+          &be,
+          sizeof (be));
+  switch (denom_sig->cipher)
+  {
+  case TALER_DENOMINATION_RSA:
+    memcpy (&buf[sizeof (be)],
+            tbuf,
+            tlen);
+    GNUNET_free (tbuf);
+    break;
+  // TODO: add case for Clause-Schnorr
+  default:
+    GNUNET_assert (0);
+  }
+
+  scratch[0] = buf;
+  param_values[0] = (void *) buf;
+  param_lengths[0] = len;
+  param_formats[0] = 1;
+  return 1;
+}
+
+
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_denom_sig (
+  const struct TALER_DenominationSignature *denom_sig)
 {
-  struct GNUNET_PQ_QueryParam res =
-  { &qconv_amount, NULL, x, sizeof (*x), 2 };
+  struct GNUNET_PQ_QueryParam res = {
+    .conv = &qconv_denom_sig,
+    .data = denom_sig,
+    .num_params = 1
+  };
+
   return res;
 }
 
@@ -199,17 +368,15 @@ qconv_json (void *cls,
 }
 
 
-/**
- * Generate query parameter for a JSON object (stored as a string
- * in the DB).
- *
- * @param x pointer to the json object to pass
- */
 struct GNUNET_PQ_QueryParam
 TALER_PQ_query_param_json (const json_t *x)
 {
-  struct GNUNET_PQ_QueryParam res =
-  { &qconv_json, NULL, x, 0, 1 };
+  struct GNUNET_PQ_QueryParam res = {
+    .conv = &qconv_json,
+    .data = x,
+    .num_params = 1
+  };
+
   return res;
 }
 
@@ -261,21 +428,16 @@ qconv_round_time (void *cls,
 }
 
 
-/**
- * Generate query parameter for an absolute time value.
- * In contrast to
- * #GNUNET_PQ_query_param_absolute_time(), this function
- * will abort (!) if the time given is not rounded!
- * The database must store a 64-bit integer.
- *
- * @param x pointer to the query parameter to pass
- * @return array entry for the query parameters to use
- */
 struct GNUNET_PQ_QueryParam
 TALER_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
 {
-  struct GNUNET_PQ_QueryParam res =
-  { &qconv_round_time, NULL, x, sizeof (*x), 1 };
+  struct GNUNET_PQ_QueryParam res = {
+    .conv = &qconv_round_time,
+    .data = x,
+    .size = sizeof (*x),
+    .num_params = 1
+  };
+
   return res;
 }
 
@@ -324,20 +486,16 @@ qconv_round_time_abs (void *cls,
 }
 
 
-/**
- * Generate query parameter for an absolute time value.
- * In contrast to
- * #GNUNET_PQ_query_param_absolute_time(), this function
- * will abort (!) if the time given is not rounded!
- * The database must store a 64-bit integer.
- *
- * @param x pointer to the query parameter to pass
- */
 struct GNUNET_PQ_QueryParam
 TALER_PQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO 
*x)
 {
-  struct GNUNET_PQ_QueryParam res =
-  { &qconv_round_time_abs, NULL, x, sizeof (*x), 1 };
+  struct GNUNET_PQ_QueryParam res = {
+    .conv = &qconv_round_time_abs,
+    .data = x,
+    .size = sizeof (*x),
+    .num_params = 1
+  };
+
   return res;
 }
 
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c
index 3d252890..57bcf6dd 100644
--- a/src/pq/pq_result_helper.c
+++ b/src/pq/pq_result_helper.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  Copyright (C) 2014, 2015, 2016 Taler Systems SA
+  Copyright (C) 2014, 2015, 2016, 2021 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
@@ -156,14 +156,6 @@ extract_amount_nbo (void *cls,
 }
 
 
-/**
- * Currency amount expected.
- *
- * @param name name of the field in the table
- * @param currency the currency to use for @a amount
- * @param[out] amount where to store the result
- * @return array entry for the result specification to use
- */
 struct GNUNET_PQ_ResultSpec
 TALER_PQ_result_spec_amount_nbo (const char *name,
                                  const char *currency,
@@ -240,14 +232,6 @@ extract_amount (void *cls,
 }
 
 
-/**
- * Currency amount expected.
- *
- * @param name name of the field in the table
- * @param currency the currency to use for @a amount
- * @param[out] amount where to store the result
- * @return array entry for the result specification to use
- */
 struct GNUNET_PQ_ResultSpec
 TALER_PQ_result_spec_amount (const char *name,
                              const char *currency,
@@ -353,13 +337,6 @@ clean_json (void *cls,
 }
 
 
-/**
- * json_t expected.
- *
- * @param name name of the field in the table
- * @param[out] jp where to store the result
- * @return array entry for the result specification to use
- */
 struct GNUNET_PQ_ResultSpec
 TALER_PQ_result_spec_json (const char *name,
                            json_t **jp)
@@ -430,16 +407,6 @@ extract_round_time (void *cls,
 }
 
 
-/**
- * Rounded absolute time expected.
- * In contrast to #GNUNET_PQ_query_param_absolute_time_nbo(),
- * this function ensures that the result is rounded and can
- * be converted to JSON.
- *
- * @param name name of the field in the table
- * @param[out] at where to store the result
- * @return array entry for the result specification to use
- */
 struct GNUNET_PQ_ResultSpec
 TALER_PQ_result_spec_absolute_time (const char *name,
                                     struct GNUNET_TIME_Absolute *at)
@@ -510,16 +477,6 @@ extract_round_time_nbo (void *cls,
 }
 
 
-/**
- * Rounded absolute time in network byte order expected.
- * In contrast to #GNUNET_PQ_query_param_absolute_time_nbo(),
- * this function ensures that the result is rounded and can
- * be converted to JSON.
- *
- * @param name name of the field in the table
- * @param[out] at where to store the result
- * @return array entry for the result specification to use
- */
 struct GNUNET_PQ_ResultSpec
 TALER_PQ_result_spec_absolute_time_nbo (const char *name,
                                         struct GNUNET_TIME_AbsoluteNBO *at)
@@ -535,4 +492,229 @@ TALER_PQ_result_spec_absolute_time_nbo (const char *name,
 }
 
 
+/**
+ * Extract data from a Postgres database @a result at row @a row.
+ *
+ * @param cls closure
+ * @param result where to extract data from
+ * @param int row to extract data from
+ * @param fname name (or prefix) of the fields to extract from
+ * @param[in,out] dst_size where to store size of result, may be NULL
+ * @param[out] dst where to store the result
+ * @return
+ *   #GNUNET_YES if all results could be extracted
+ *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+ */
+static enum GNUNET_GenericReturnValue
+extract_denom_pub (void *cls,
+                   PGresult *result,
+                   int row,
+                   const char *fname,
+                   size_t *dst_size,
+                   void *dst)
+{
+  struct TALER_DenominationPublicKey *pk = dst;
+  size_t len;
+  const char *res;
+  int fnum;
+  uint32_t be[2];
+
+  (void) cls;
+  fnum = PQfnumber (result,
+                    fname);
+  if (fnum < 0)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  if (PQgetisnull (result,
+                   row,
+                   fnum))
+    return GNUNET_NO;
+
+  /* if a field is null, continue but
+   * remember that we now return a different result */
+  len = PQgetlength (result,
+                     row,
+                     fnum);
+  res = PQgetvalue (result,
+                    row,
+                    fnum);
+  if (len < sizeof (be))
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  memcpy (be,
+          res,
+          sizeof (be));
+  res += sizeof (be);
+  len -= sizeof (be);
+  pk->cipher = ntohl (be[0]);
+  pk->age_mask = ntohl (be[1]);
+  switch (pk->cipher)
+  {
+  case TALER_DENOMINATION_RSA:
+    pk->details.rsa_public_key
+      = GNUNET_CRYPTO_rsa_public_key_decode (res,
+                                             len);
+    if (NULL == pk->details.rsa_public_key)
+    {
+      GNUNET_break (0);
+      return GNUNET_SYSERR;
+    }
+    return GNUNET_OK;
+  // FIXME: add CS case!
+  default:
+    GNUNET_break (0);
+  }
+  return GNUNET_SYSERR;
+}
+
+
+/**
+ * Function called to clean up memory allocated
+ * by a #GNUNET_PQ_ResultConverter.
+ *
+ * @param cls closure
+ * @param rd result data to clean up
+ */
+static void
+clean_denom_pub (void *cls,
+                 void *rd)
+{
+  struct TALER_DenominationPublicKey *denom_pub = rd;
+
+  (void) cls;
+  TALER_denom_pub_free (denom_pub);
+}
+
+
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_denom_pub (const char *name,
+                                struct TALER_DenominationPublicKey *denom_pub)
+{
+  struct GNUNET_PQ_ResultSpec res = {
+    .conv = &extract_denom_pub,
+    .cleaner = &clean_denom_pub,
+    .dst = (void *) denom_pub,
+    .fname = name
+  };
+
+  return res;
+}
+
+
+/**
+ * Extract data from a Postgres database @a result at row @a row.
+ *
+ * @param cls closure
+ * @param result where to extract data from
+ * @param int row to extract data from
+ * @param fname name (or prefix) of the fields to extract from
+ * @param[in,out] dst_size where to store size of result, may be NULL
+ * @param[out] dst where to store the result
+ * @return
+ *   #GNUNET_YES if all results could be extracted
+ *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+ */
+static enum GNUNET_GenericReturnValue
+extract_denom_sig (void *cls,
+                   PGresult *result,
+                   int row,
+                   const char *fname,
+                   size_t *dst_size,
+                   void *dst)
+{
+  struct TALER_DenominationSignature *sig = dst;
+  size_t len;
+  const char *res;
+  int fnum;
+  uint32_t be;
+
+  (void) cls;
+  fnum = PQfnumber (result,
+                    fname);
+  if (fnum < 0)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  if (PQgetisnull (result,
+                   row,
+                   fnum))
+    return GNUNET_NO;
+
+  /* if a field is null, continue but
+   * remember that we now return a different result */
+  len = PQgetlength (result,
+                     row,
+                     fnum);
+  res = PQgetvalue (result,
+                    row,
+                    fnum);
+  if (len < sizeof (be))
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  memcpy (&be,
+          res,
+          sizeof (be));
+  res += sizeof (be);
+  len -= sizeof (be);
+  sig->cipher = ntohl (be);
+  switch (sig->cipher)
+  {
+  case TALER_DENOMINATION_RSA:
+    sig->details.rsa_signature
+      = GNUNET_CRYPTO_rsa_signature_decode (res,
+                                            len);
+    if (NULL == sig->details.rsa_signature)
+    {
+      GNUNET_break (0);
+      return GNUNET_SYSERR;
+    }
+    return GNUNET_OK;
+  // FIXME: add CS case!
+  default:
+    GNUNET_break (0);
+  }
+  return GNUNET_SYSERR;
+}
+
+
+/**
+ * Function called to clean up memory allocated
+ * by a #GNUNET_PQ_ResultConverter.
+ *
+ * @param cls closure
+ * @param rd result data to clean up
+ */
+static void
+clean_denom_sig (void *cls,
+                 void *rd)
+{
+  struct TALER_DenominationSignature *denom_sig = rd;
+
+  (void) cls;
+  TALER_denom_sig_free (denom_sig);
+}
+
+
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_denom_sig (const char *name,
+                                struct TALER_DenominationSignature *denom_sig)
+{
+  struct GNUNET_PQ_ResultSpec res = {
+    .conv = &extract_denom_sig,
+    .cleaner = &clean_denom_sig,
+    .dst = (void *) denom_sig,
+    .fname = name
+  };
+
+  return res;
+}
+
+
 /* end of pq_result_helper.c */
diff --git a/src/util/denom.c b/src/util/denom.c
index 32c3469f..694f5ff8 100644
--- a/src/util/denom.c
+++ b/src/util/denom.c
@@ -112,4 +112,61 @@ TALER_denom_pub_verify (const struct 
TALER_DenominationPublicKey *denom_pub,
 }
 
 
+void
+TALER_denom_pub_free (struct TALER_DenominationPublicKey *denom_pub)
+{
+  switch (denom_pub->cipher)
+  {
+  case TALER_DENOMINATION_RSA:
+    if (NULL != denom_pub->details.rsa_public_key)
+    {
+      GNUNET_CRYPTO_rsa_public_key_free (denom_pub->details.rsa_public_key);
+      denom_pub->details.rsa_public_key = NULL;
+    }
+    return;
+  // TODO: add case for Clause-Schnorr
+  default:
+    GNUNET_assert (0);
+  }
+}
+
+
+void
+TALER_denom_priv_free (struct TALER_DenominationPrivateKey *denom_priv)
+{
+  switch (denom_priv->cipher)
+  {
+  case TALER_DENOMINATION_RSA:
+    if (NULL != denom_priv->details.rsa_private_key)
+    {
+      GNUNET_CRYPTO_rsa_private_key_free (denom_priv->details.rsa_private_key);
+      denom_priv->details.rsa_private_key = NULL;
+    }
+    return;
+  // TODO: add case for Clause-Schnorr
+  default:
+    GNUNET_assert (0);
+  }
+}
+
+
+void
+TALER_denom_sig_free (struct TALER_DenominationSignature *denom_sig)
+{
+  switch (denom_sig->cipher)
+  {
+  case TALER_DENOMINATION_RSA:
+    if (NULL != denom_sig->details.rsa_signature)
+    {
+      GNUNET_CRYPTO_rsa_signature_free (denom_sig->details.rsa_signature);
+      denom_sig->details.rsa_signature = NULL;
+    }
+    return;
+  // TODO: add case for Clause-Schnorr
+  default:
+    GNUNET_assert (0);
+  }
+}
+
+
 /* end of denom.c */

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]