donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit ece5ed60dc92b922df374fe8d19c79b7e6168a66
parent ecc22e18512a964773d27bd7ef7096ff57e6dec2
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
Date:   Wed, 29 May 2024 13:59:23 +0200

work on pq_query_helper

Diffstat:
Msrc/donaudb/pg_insert_submitted_receipts.c | 2+-
Asrc/pq/pq_common.h | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/pq/pq_query_helper.c | 498+++++++++++++++++++++++++------------------------------------------------------
3 files changed, 210 insertions(+), 340 deletions(-)

diff --git a/src/donaudb/pg_insert_submitted_receipts.c b/src/donaudb/pg_insert_submitted_receipts.c @@ -89,6 +89,6 @@ DH_PG_insert_submitted_receipts ( params, rs); GNUNET_PQ_cleanup_query_params_closures (params); - // FIXME check conflicted rs + // FIXME log conflicted rs return qs; } diff --git a/src/pq/pq_common.h b/src/pq/pq_common.h @@ -0,0 +1,50 @@ +/* + This file is part of TALER + Copyright (C) 2023 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 <http://www.gnu.org/licenses/> +*/ +/** + * @file pq/pq_common.h + * @brief common defines for the pq functions + * @author Johannes Casaburi + */ +#ifndef DONAU_PQ_COMMON_H_ +#define DONAU_PQ_COMMON_H_ + +#include "taler/taler_util.h" + +/** + * Internal types that are supported as TALER-exchange-specific array types. + * + * To support a new type, + * 1. add a new entry into this list, + * 2. for query-support, implement the size calculation and memory copying in + * qconv_array() accordingly, in pq_query_helper.c + * 3. provide a query-API for arrays of the type, by calling + * query_param_array_generic with the appropriate parameters, + * in pq_query_helper.c + * 4. for result-support, implement memory copying by adding another case + * to extract_array_generic, in pq_result_helper.c + * 5. provide a result-spec-API for arrays of the type, + * in pq_result_helper.c + * 6. expose the API's in taler_pq_lib.h + */ +enum DONAU_PQ_ArrayType +{ + DONAU_PQ_array_of_blinded_du_sig, + DONAU_PQ_array_of_unblinded_du_sig, +}; + + +#endif /* DONAU_PQ_COMMON_H_ */ +/* end of pg/pq_common.h */ diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c @@ -23,6 +23,7 @@ #include <gnunet/gnunet_pq_lib.h> #include <taler/taler_pq_lib.h> #include "donau_util.h" +#include "pq_common.h" /** @@ -197,7 +198,7 @@ struct qconv_array_cls /** * Type of the array elements */ - // enum TALER_PQ_ArrayType typ; + enum DONAU_PQ_ArrayType typ; /** * Oid of the array elements @@ -294,91 +295,94 @@ qconv_array ( } else /* sizes are different per element */ { - // switch (meta->typ) - // { - // case TALER_PQ_array_of_amount_currency: - // { - // const struct TALER_Amount *amounts = data; - // Oid oid_v; - // Oid oid_f; - // Oid oid_c; - - // buffer_lengths = GNUNET_new_array (num, size_t); - // /* hoist out of loop? */ - // GNUNET_assert (GNUNET_OK == - // GNUNET_PQ_get_oid_by_name (meta->db, - // "int8", - // &oid_v)); - // GNUNET_assert (GNUNET_OK == - // GNUNET_PQ_get_oid_by_name (meta->db, - // "int4", - // &oid_f)); - // GNUNET_assert (GNUNET_OK == - // GNUNET_PQ_get_oid_by_name (meta->db, - // "varchar", - // &oid_c)); - // for (size_t i = 0; i<num; i++) - // { - // struct TALER_PQ_AmountCurrencyP am; - // size_t len; - - // len = TALER_PQ_make_taler_pq_amount_currency_ ( - // &amounts[i], - // oid_v, - // oid_f, - // oid_c, - // &am); - // buffer_lengths[i] = len; - // y = total_size; - // total_size += len; - // RETURN_UNLESS (total_size >= y); - // } - // sizes = buffer_lengths; - // break; - // } - // case TALER_PQ_array_of_blinded_denom_sig: - // { - const struct DONAU_BlindedDonationUnitSignature *du_sigs = data; - size_t len; - - buffers = GNUNET_new_array (num, void *); - buffer_lengths = GNUNET_new_array (num, size_t); - - for (size_t i = 0; i<num; i++) + switch (meta->typ) { - const struct GNUNET_CRYPTO_BlindedSignature *bs = - du_sigs[i].blinded_sig; - - switch (bs->cipher) + case DONAU_PQ_array_of_blinded_du_sig: { - case GNUNET_CRYPTO_BSA_RSA: - len = GNUNET_CRYPTO_rsa_signature_encode ( - bs->details.blinded_rsa_signature, - &buffers[i]); - RETURN_UNLESS (len != 0); + const struct DONAU_BlindedDonationUnitSignature *du_sigs = data; + size_t len; + + buffers = GNUNET_new_array (num, void *); + buffer_lengths = GNUNET_new_array (num, size_t); + + for (size_t i = 0; i<num; i++) + { + const struct GNUNET_CRYPTO_BlindedSignature *bs = + du_sigs[i].blinded_sig; + + switch (bs->cipher) + { + case GNUNET_CRYPTO_BSA_RSA: + len = GNUNET_CRYPTO_rsa_signature_encode ( + bs->details.blinded_rsa_signature, + &buffers[i]); + RETURN_UNLESS (len != 0); + break; + case GNUNET_CRYPTO_BSA_CS: + len = sizeof (bs->details.blinded_cs_answer); + break; + default: + GNUNET_assert (0); + break; + } + + /* for the cipher and marker */ + len += 2 * sizeof(uint32_t); + buffer_lengths[i] = len; + + y = total_size; + total_size += len; + RETURN_UNLESS (total_size >= y); + } + sizes = buffer_lengths; break; - case GNUNET_CRYPTO_BSA_CS: - len = sizeof (bs->details.blinded_cs_answer); + } + case DONAU_PQ_array_of_unblinded_du_sig: // FIXME implement + { + const struct DONAU_BlindedDonationUnitSignature *du_sigs = data; + size_t len; + + buffers = GNUNET_new_array (num, void *); + buffer_lengths = GNUNET_new_array (num, size_t); + + for (size_t i = 0; i<num; i++) + { + const struct GNUNET_CRYPTO_BlindedSignature *bs = + du_sigs[i].blinded_sig; + + switch (bs->cipher) + { + case GNUNET_CRYPTO_BSA_RSA: + len = GNUNET_CRYPTO_rsa_signature_encode ( + bs->details.blinded_rsa_signature, + &buffers[i]); + RETURN_UNLESS (len != 0); + break; + case GNUNET_CRYPTO_BSA_CS: + len = sizeof (bs->details.blinded_cs_answer); + break; + default: + GNUNET_assert (0); + break; + } + + /* for the cipher and marker */ + len += 2 * sizeof(uint32_t); + buffer_lengths[i] = len; + + y = total_size; + total_size += len; + RETURN_UNLESS (total_size >= y); + } + sizes = buffer_lengths; break; - default: + } + default: + { GNUNET_assert (0); break; } - - /* for the cipher and marker */ - len += 2 * sizeof(uint32_t); - buffer_lengths[i] = len; - - y = total_size; - total_size += len; - RETURN_UNLESS (total_size >= y); } - sizes = buffer_lengths; - // break; - // } - // default: - // GNUNET_assert (0); - // } } RETURN_UNLESS (INT_MAX > total_size); @@ -411,140 +415,82 @@ qconv_array ( *(uint32_t *) out = htonl (sz); out += sizeof(uint32_t); - // switch (meta->typ) - // { - // case TALER_PQ_array_of_amount: - // { - // const struct TALER_Amount *amounts = data; - // Oid oid_v; - // Oid oid_f; - - // /* hoist out of loop? */ - // GNUNET_assert (GNUNET_OK == - // GNUNET_PQ_get_oid_by_name (meta->db, - // "int8", - // &oid_v)); - // GNUNET_assert (GNUNET_OK == - // GNUNET_PQ_get_oid_by_name (meta->db, - // "int4", - // &oid_f)); - // { - // struct TALER_PQ_AmountP am - // = TALER_PQ_make_taler_pq_amount_ ( - // &amounts[i], - // oid_v, - // oid_f); - - // GNUNET_memcpy (out, - // &am, - // sizeof(am)); - // } - // break; - // } - // case TALER_PQ_array_of_amount_currency: - // { - // const struct TALER_Amount *amounts = data; - // Oid oid_v; - // Oid oid_f; - // Oid oid_c; - - // /* hoist out of loop? */ - // GNUNET_assert (GNUNET_OK == - // GNUNET_PQ_get_oid_by_name (meta->db, - // "int8", - // &oid_v)); - // GNUNET_assert (GNUNET_OK == - // GNUNET_PQ_get_oid_by_name (meta->db, - // "int4", - // &oid_f)); - // GNUNET_assert (GNUNET_OK == - // GNUNET_PQ_get_oid_by_name (meta->db, - // "varchar", - // &oid_c)); - // { - // struct TALER_PQ_AmountCurrencyP am; - // size_t len; - - // len = TALER_PQ_make_taler_pq_amount_currency_ ( - // &amounts[i], - // oid_v, - // oid_f, - // oid_c, - // &am); - // GNUNET_memcpy (out, - // &am, - // len); - // } - // break; - // } - // case TALER_PQ_array_of_blinded_denom_sig: - // { - const struct DONAU_BlindedDonationUnitSignature *denom_sigs = data; - const struct GNUNET_CRYPTO_BlindedSignature *bs = - denom_sigs[i].blinded_sig; - uint32_t be[2]; - - be[0] = htonl ((uint32_t) bs->cipher); - be[1] = htonl (0x01); /* magic margker: blinded */ - GNUNET_memcpy (out, - &be, - sizeof(be)); - out += sizeof(be); - sz -= sizeof(be); - - switch (bs->cipher) + switch (meta->typ) { - case GNUNET_CRYPTO_BSA_RSA: - /* For RSA, 'same_sized' must have been false */ - GNUNET_assert (NULL != buffers); - GNUNET_memcpy (out, - buffers[i], - sz); - break; - case GNUNET_CRYPTO_BSA_CS: - GNUNET_memcpy (out, - &bs->details.blinded_cs_answer, - sz); - break; + case DONAU_PQ_array_of_blinded_du_sig: + { + const struct DONAU_BlindedDonationUnitSignature *denom_sigs = data; + const struct GNUNET_CRYPTO_BlindedSignature *bs = + denom_sigs[i].blinded_sig; + uint32_t be[2]; + + be[0] = htonl ((uint32_t) bs->cipher); + be[1] = htonl (0x01); /* magic margker: blinded */ + GNUNET_memcpy (out, + &be, + sizeof(be)); + out += sizeof(be); + sz -= sizeof(be); + + switch (bs->cipher) + { + case GNUNET_CRYPTO_BSA_RSA: + /* For RSA, 'same_sized' must have been false */ + GNUNET_assert (NULL != buffers); + GNUNET_memcpy (out, + buffers[i], + sz); + break; + case GNUNET_CRYPTO_BSA_CS: + GNUNET_memcpy (out, + &bs->details.blinded_cs_answer, + sz); + break; + default: + GNUNET_assert (0); + } + break; + } + case DONAU_PQ_array_of_unblinded_du_sig: // FIXME implement + { + const struct DONAU_BlindedDonationUnitSignature *denom_sigs = data; + const struct GNUNET_CRYPTO_BlindedSignature *bs = + denom_sigs[i].blinded_sig; + uint32_t be[2]; + + be[0] = htonl ((uint32_t) bs->cipher); + be[1] = htonl (0x00); /* magic margker: unblinded */ + GNUNET_memcpy (out, + &be, + sizeof(be)); + out += sizeof(be); + sz -= sizeof(be); + + switch (bs->cipher) + { + case GNUNET_CRYPTO_BSA_RSA: + /* For RSA, 'same_sized' must have been false */ + GNUNET_assert (NULL != buffers); + GNUNET_memcpy (out, + buffers[i], + sz); + break; + case GNUNET_CRYPTO_BSA_CS: + GNUNET_memcpy (out, + &bs->details.blinded_cs_answer, + sz); + break; + default: + GNUNET_assert (0); + } + break; + } default: - GNUNET_assert (0); + { + GNUNET_assert (0); + break; + } } - // break; - // } - // case TALER_PQ_array_of_blinded_coin_hash: - // { - // const struct TALER_BlindedCoinHashP *coin_hs = data; - - // GNUNET_memcpy (out, - // &coin_hs[i], - // sizeof(struct TALER_BlindedCoinHashP)); - - // break; - // } - // case TALER_PQ_array_of_denom_hash: - // { - // const struct TALER_DenominationHashP *denom_hs = data; - - // GNUNET_memcpy (out, - // &denom_hs[i], - // sizeof(struct TALER_DenominationHashP)); - // break; - // } - // case TALER_PQ_array_of_hash_code: - // { - // const struct GNUNET_HashCode *hashes = data; - - // GNUNET_memcpy (out, - // &hashes[i], - // sizeof(struct GNUNET_HashCode)); - // break; - // } - // default: - // { - // GNUNET_assert (0); - // break; - // } - // } out += sz; } } @@ -598,13 +544,13 @@ query_param_array_generic ( const void *elements, const size_t *sizes, size_t same_size, - // enum TALER_PQ_ArrayType typ, + enum DONAU_PQ_ArrayType typ, Oid oid, struct GNUNET_PQ_Context *db) { struct qconv_array_cls *meta = GNUNET_new (struct qconv_array_cls); - // meta->typ = typ; + meta->typ = typ; meta->oid = oid; meta->sizes = sizes; meta->same_size = same_size; @@ -643,7 +589,7 @@ DONAU_PQ_query_param_array_blinded_donation_unit_sig ( du_sigs, NULL, 0, - // TALER_PQ_array_of_blinded_du_sig, + DONAU_PQ_array_of_blinded_du_sig, oid, NULL); } @@ -666,7 +612,7 @@ DONAU_PQ_query_param_array_donation_unit_sig ( du_sigs, NULL, 0, - // TALER_PQ_array_of_blinded_du_sig, + DONAU_PQ_array_of_unblinded_du_sig, oid, NULL); } @@ -747,124 +693,6 @@ extract_array_generic ( { char *in = data + sizeof(header); - - // switch (info->typ) - // { - // case TALER_PQ_array_of_amount: - // { - // struct TALER_Amount *amounts; - // if (NULL != dst_size) - // *dst_size = sizeof(struct TALER_Amount) * (header.dim); - - // amounts = GNUNET_new_array (header.dim, - // struct TALER_Amount); - // *((void **) dst) = amounts; - - // for (uint32_t i = 0; i < header.dim; i++) - // { - // struct TALER_PQ_AmountP ap; - // struct TALER_Amount *amount = &amounts[i]; - // uint32_t val; - // size_t sz; - - // GNUNET_memcpy (&val, - // in, - // sizeof(val)); - // sz = ntohl (val); - // in += sizeof(val); - - // /* total size for this array-entry */ - // FAIL_IF (sizeof(ap) != sz); - - // GNUNET_memcpy (&ap, - // in, - // sz); - // FAIL_IF (2 != ntohl (ap.cnt)); - - // amount->value = GNUNET_ntohll (ap.v); - // amount->fraction = ntohl (ap.f); - // GNUNET_memcpy (amount->currency, - // info->currency, - // TALER_CURRENCY_LEN); - - // in += sizeof(struct TALER_PQ_AmountP); - // } - // return GNUNET_OK; - // } - // case TALER_PQ_array_of_denom_hash: - // if (NULL != dst_size) - // *dst_size = sizeof(struct TALER_DenominationHashP) * (header.dim); - // out = GNUNET_new_array (header.dim, - // struct TALER_DenominationHashP); - // *((void **) dst) = out; - // for (uint32_t i = 0; i < header.dim; i++) - // { - // uint32_t val; - // size_t sz; - - // GNUNET_memcpy (&val, - // in, - // sizeof(val)); - // sz = ntohl (val); - // FAIL_IF (sz != sizeof(struct TALER_DenominationHashP)); - // in += sizeof(uint32_t); - // *(struct TALER_DenominationHashP *) out = - // *(struct TALER_DenominationHashP *) in; - // in += sz; - // out += sz; - // } - // return GNUNET_OK; - - // case TALER_PQ_array_of_hash_code: - // if (NULL != dst_size) - // *dst_size = sizeof(struct GNUNET_HashCode) * (header.dim); - // out = GNUNET_new_array (header.dim, - // struct GNUNET_HashCode); - // *((void **) dst) = out; - // for (uint32_t i = 0; i < header.dim; i++) - // { - // uint32_t val; - // size_t sz; - - // GNUNET_memcpy (&val, - // in, - // sizeof(val)); - // sz = ntohl (val); - // FAIL_IF (sz != sizeof(struct GNUNET_HashCode)); - // in += sizeof(uint32_t); - // *(struct GNUNET_HashCode *) out = - // *(struct GNUNET_HashCode *) in; - // in += sz; - // out += sz; - // } - // return GNUNET_OK; - - // case TALER_PQ_array_of_blinded_coin_hash: - // if (NULL != dst_size) - // *dst_size = sizeof(struct TALER_BlindedCoinHashP) * (header.dim); - // out = GNUNET_new_array (header.dim, - // struct TALER_BlindedCoinHashP); - // *((void **) dst) = out; - // for (uint32_t i = 0; i < header.dim; i++) - // { - // uint32_t val; - // size_t sz; - - // GNUNET_memcpy (&val, - // in, - // sizeof(val)); - // sz = ntohl (val); - // FAIL_IF (sz != sizeof(struct TALER_BlindedCoinHashP)); - // in += sizeof(uint32_t); - // *(struct TALER_BlindedCoinHashP *) out = - // *(struct TALER_BlindedCoinHashP *) in; - // in += sz; - // out += sz; - // } - // return GNUNET_OK; - - // case TALER_PQ_array_of_blinded_denom_sig: - // { struct DONAU_BlindedDonationUnitSignature *du_sigs; if (0 == header.dim) { @@ -933,10 +761,6 @@ extract_array_generic ( in += sz; } return GNUNET_OK; - // } - // default: - // FAIL_IF (true); - // } } FAIL: GNUNET_free (*(void **) dst); @@ -959,14 +783,10 @@ array_cleanup (void *cls, (NULL != info->sizes)) GNUNET_free (*(info->sizes)); - /* Clean up signatures, if applicable */ - // if (TALER_PQ_array_of_blinded_denom_sig == info->typ) - // { struct DONAU_BlindedDonationUnitSignature *du_sigs = *dst; GNUNET_assert (NULL != info->num); for (size_t i = 0; i < *info->num; i++) GNUNET_free (du_sigs[i].blinded_sig); - // } GNUNET_free (cls); GNUNET_free (*dst);