pq_common.c (1969B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2023 Taler Systems SA 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 pq/pq_common.c 18 * @brief common defines for the pq functions 19 * @author Özgür Kesim 20 */ 21 #include "pq_common.h" 22 23 struct TALER_PQ_AmountP 24 TALER_PQ_make_taler_pq_amount_ ( 25 const struct TALER_Amount *amount, 26 uint32_t oid_v, 27 uint32_t oid_f) 28 { 29 struct TALER_PQ_AmountP rval = { 30 .cnt = htonl (2), 31 .oid_v = htonl (oid_v), 32 .oid_f = htonl (oid_f), 33 .sz_v = htonl (sizeof((amount)->value)), 34 .sz_f = htonl (sizeof((amount)->fraction)), 35 .v = GNUNET_htonll ((amount)->value), 36 .f = htonl ((amount)->fraction) 37 }; 38 39 return rval; 40 } 41 42 43 size_t 44 TALER_PQ_make_taler_pq_amount_currency_ ( 45 const struct TALER_Amount *amount, 46 uint32_t oid_v, 47 uint32_t oid_f, 48 uint32_t oid_c, 49 struct TALER_PQ_AmountCurrencyP *rval) 50 { 51 size_t clen = strlen (amount->currency); 52 53 GNUNET_assert (clen < TALER_CURRENCY_LEN); 54 rval->cnt = htonl (3); 55 rval->oid_v = htonl (oid_v); 56 rval->oid_f = htonl (oid_f); 57 rval->oid_c = htonl (oid_c); 58 rval->sz_v = htonl (sizeof(amount->value)); 59 rval->sz_f = htonl (sizeof(amount->fraction)); 60 rval->sz_c = htonl (clen); 61 rval->v = GNUNET_htonll (amount->value); 62 rval->f = htonl (amount->fraction); 63 memcpy (rval->c, 64 amount->currency, 65 clen); 66 return sizeof (*rval) - TALER_CURRENCY_LEN + clen; 67 }