donau

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

json_pack.c (2379B)


      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 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     return ps;
     41   bsp = pk->bsign_pub_key;
     42   switch (bsp->cipher)
     43   {
     44   case GNUNET_CRYPTO_BSA_INVALID:
     45     break;
     46   case GNUNET_CRYPTO_BSA_RSA:
     47     ps.object
     48       = GNUNET_JSON_PACK (
     49           GNUNET_JSON_pack_string ("cipher",
     50                                    "RSA"),
     51           GNUNET_JSON_pack_rsa_public_key ("rsa_public_key",
     52                                            bsp->details.rsa_public_key),
     53           GNUNET_JSON_pack_data_auto ("pub_key_hash",
     54                                       &bsp->pub_key_hash));
     55     return ps;
     56   case GNUNET_CRYPTO_BSA_CS:
     57     ps.object
     58       = GNUNET_JSON_PACK (
     59           GNUNET_JSON_pack_string ("cipher",
     60                                    "CS"),
     61           GNUNET_JSON_pack_data_varsize ("cs_public_key",
     62                                          &bsp->details.cs_public_key,
     63                                          sizeof (bsp->details.cs_public_key)),
     64           GNUNET_JSON_pack_data_auto ("pub_key_hash",
     65                                       &bsp->pub_key_hash));
     66     return ps;
     67   }
     68   GNUNET_assert (0);
     69   return ps;
     70 }
     71 
     72 
     73 /* End of json/json_pack.c */