LCOV - code coverage report
Current view: top level - json - json_pack.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 22 32 68.8 %
Date: 2021-08-30 06:43:37 Functions: 6 10 60.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2021 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             :  */
      21             : #include "platform.h"
      22             : #include <gnunet/gnunet_util_lib.h>
      23             : #include "taler_util.h"
      24             : #include "taler_json_lib.h"
      25             : 
      26             : 
      27             : struct GNUNET_JSON_PackSpec
      28           0 : TALER_JSON_pack_time_abs (const char *name,
      29             :                           struct GNUNET_TIME_Absolute at)
      30             : {
      31           0 :   GNUNET_assert (GNUNET_OK ==
      32             :                  GNUNET_TIME_round_abs (&at));
      33           0 :   return GNUNET_JSON_pack_time_abs (name,
      34             :                                     at);
      35             : }
      36             : 
      37             : 
      38             : struct GNUNET_JSON_PackSpec
      39        1080 : TALER_JSON_pack_time_abs_human (const char *name,
      40             :                                 struct GNUNET_TIME_Absolute at)
      41             : {
      42        2160 :   struct GNUNET_JSON_PackSpec ps = {
      43             :     .field_name = name,
      44        1080 :     .object = json_string (
      45             :       GNUNET_STRINGS_absolute_time_to_string (at))
      46             :   };
      47             : 
      48        1080 :   return ps;
      49             : }
      50             : 
      51             : 
      52             : struct GNUNET_JSON_PackSpec
      53           0 : TALER_JSON_pack_time_abs_nbo (const char *name,
      54             :                               struct GNUNET_TIME_AbsoluteNBO at)
      55             : {
      56           0 :   return TALER_JSON_pack_time_abs (name,
      57             :                                    GNUNET_TIME_absolute_ntoh (at));
      58             : }
      59             : 
      60             : 
      61             : struct GNUNET_JSON_PackSpec
      62          10 : TALER_JSON_pack_time_abs_nbo_human (const char *name,
      63             :                                     struct GNUNET_TIME_AbsoluteNBO at)
      64             : {
      65          10 :   return TALER_JSON_pack_time_abs_human (name,
      66             :                                          GNUNET_TIME_absolute_ntoh (at));
      67             : }
      68             : 
      69             : 
      70             : struct GNUNET_JSON_PackSpec
      71           0 : TALER_JSON_pack_time_rel (const char *name,
      72             :                           struct GNUNET_TIME_Relative rt)
      73             : {
      74           0 :   GNUNET_assert (GNUNET_OK ==
      75             :                  GNUNET_TIME_round_rel (&rt));
      76           0 :   return GNUNET_JSON_pack_time_rel (name,
      77             :                                     rt);
      78             : }
      79             : 
      80             : 
      81             : struct GNUNET_JSON_PackSpec
      82           0 : TALER_JSON_pack_time_rel_nbo (const char *name,
      83             :                               struct GNUNET_TIME_RelativeNBO rt)
      84             : {
      85           0 :   return TALER_JSON_pack_time_rel (name,
      86             :                                    GNUNET_TIME_relative_ntoh (rt));
      87             : }
      88             : 
      89             : 
      90             : struct GNUNET_JSON_PackSpec
      91           6 : TALER_JSON_pack_denomination_public_key (const char *name,
      92             :                                          const struct
      93             :                                          TALER_DenominationPublicKey *pk)
      94             : {
      95          12 :   return GNUNET_JSON_pack_rsa_public_key (name,
      96           6 :                                           pk->rsa_public_key);
      97             : }
      98             : 
      99             : 
     100             : struct GNUNET_JSON_PackSpec
     101          80 : TALER_JSON_pack_denomination_signature (const char *name,
     102             :                                         const struct
     103             :                                         TALER_DenominationSignature *sig)
     104             : {
     105         160 :   return GNUNET_JSON_pack_rsa_signature (name,
     106          80 :                                          sig->rsa_signature);
     107             : }
     108             : 
     109             : 
     110             : struct GNUNET_JSON_PackSpec
     111        6031 : TALER_JSON_pack_amount (const char *name,
     112             :                         const struct TALER_Amount *amount)
     113             : {
     114       12062 :   struct GNUNET_JSON_PackSpec ps = {
     115             :     .field_name = name,
     116             :     .object = (NULL != amount)
     117        6031 :     ? TALER_JSON_from_amount (amount)
     118        6031 :     : NULL
     119             :   };
     120             : 
     121        6031 :   return ps;
     122             : }
     123             : 
     124             : 
     125             : struct GNUNET_JSON_PackSpec
     126           5 : TALER_JSON_pack_amount_nbo (const char *name,
     127             :                             const struct TALER_AmountNBO *amount)
     128             : {
     129          10 :   struct GNUNET_JSON_PackSpec ps = {
     130             :     .field_name = name,
     131             :     .object = (NULL != amount)
     132           5 :     ? TALER_JSON_from_amount_nbo (amount)
     133           5 :     : NULL
     134             :   };
     135             : 
     136           5 :   return ps;
     137             : }
     138             : 
     139             : 
     140             : /* End of json/json_pack.c */

Generated by: LCOV version 1.14