Line data Source code
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 "platform.h" 22 : #include "pq_common.h" 23 : 24 : struct TALER_PQ_AmountP 25 42885 : TALER_PQ_make_taler_pq_amount_ ( 26 : const struct TALER_Amount *amount, 27 : uint32_t oid_v, 28 : uint32_t oid_f) 29 : { 30 85770 : struct TALER_PQ_AmountP rval = { 31 42885 : .cnt = htonl (2), 32 42885 : .oid_v = htonl (oid_v), 33 42885 : .oid_f = htonl (oid_f), 34 42885 : .sz_v = htonl (sizeof((amount)->value)), 35 42885 : .sz_f = htonl (sizeof((amount)->fraction)), 36 42885 : .v = GNUNET_htonll ((amount)->value), 37 42885 : .f = htonl ((amount)->fraction) 38 : }; 39 : 40 42885 : return rval; 41 : } 42 : 43 : 44 : size_t 45 49 : TALER_PQ_make_taler_pq_amount_currency_ ( 46 : const struct TALER_Amount *amount, 47 : uint32_t oid_v, 48 : uint32_t oid_f, 49 : uint32_t oid_c, 50 : struct TALER_PQ_AmountCurrencyP *rval) 51 : { 52 49 : size_t clen = strlen (amount->currency); 53 : 54 49 : GNUNET_assert (clen < TALER_CURRENCY_LEN); 55 49 : rval->cnt = htonl (3); 56 49 : rval->oid_v = htonl (oid_v); 57 49 : rval->oid_f = htonl (oid_f); 58 49 : rval->oid_c = htonl (oid_c); 59 49 : rval->sz_v = htonl (sizeof(amount->value)); 60 49 : rval->sz_f = htonl (sizeof(amount->fraction)); 61 49 : rval->sz_c = htonl (clen); 62 49 : rval->v = GNUNET_htonll (amount->value); 63 49 : rval->f = htonl (amount->fraction); 64 49 : memcpy (rval->c, 65 49 : amount->currency, 66 : clen); 67 49 : return sizeof (*rval) - TALER_CURRENCY_LEN + clen; 68 : }