json_pack.c (2431B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2024 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 donau/src/json/json_pack.c 18 * @brief helper functions for JSON object packing 19 * @author Christian Grothoff 20 * @author Lukas Matyja 21 */ 22 #include "donau_config.h" 23 #include "donau_json_lib.h" 24 #include <gnunet/gnunet_util_lib.h> 25 #include <taler/taler_util.h> 26 #include <taler/taler_json_lib.h> 27 #include <donau_util.h> 28 29 struct GNUNET_JSON_PackSpec 30 DONAU_JSON_pack_donation_unit_pub ( 31 const char *name, 32 const struct DONAU_DonationUnitPublicKey *pk) 33 { 34 const struct GNUNET_CRYPTO_BlindSignPublicKey *bsp; 35 struct GNUNET_JSON_PackSpec ps = { 36 .field_name = name, 37 }; 38 39 if ( (NULL == pk) || 40 (NULL == pk->bsign_pub_key) ) 41 return ps; 42 bsp = pk->bsign_pub_key; 43 switch (bsp->cipher) 44 { 45 case GNUNET_CRYPTO_BSA_INVALID: 46 break; 47 case GNUNET_CRYPTO_BSA_RSA: 48 ps.object 49 = GNUNET_JSON_PACK ( 50 GNUNET_JSON_pack_string ("cipher", 51 "RSA"), 52 GNUNET_JSON_pack_rsa_public_key ("rsa_public_key", 53 bsp->details.rsa_public_key), 54 GNUNET_JSON_pack_data_auto ("pub_key_hash", 55 &bsp->pub_key_hash)); 56 return ps; 57 case GNUNET_CRYPTO_BSA_CS: 58 ps.object 59 = GNUNET_JSON_PACK ( 60 GNUNET_JSON_pack_string ("cipher", 61 "CS"), 62 GNUNET_JSON_pack_data_varsize ("cs_public_key", 63 &bsp->details.cs_public_key, 64 sizeof (bsp->details.cs_public_key)), 65 GNUNET_JSON_pack_data_auto ("pub_key_hash", 66 &bsp->pub_key_hash)); 67 return ps; 68 } 69 GNUNET_assert (0); 70 return ps; 71 } 72 73 74 /* End of json/json_pack.c */