LCOV - code coverage report
Current view: top level - backenddb - pg_insert_token_family_key.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 29 37 78.4 %
Date: 2025-06-23 16:22:09 Functions: 1 1 100.0 %

          Line data    Source code
       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 backenddb/pg_insert_token_family_key.c
      18             :  * @brief Implementation of the insert_token_family_key function for Postgres
      19             :  * @author Christian Blättler
      20             :  */
      21             : #include "platform.h"
      22             : #include <gnunet/gnunet_common.h>
      23             : #include <gnunet/gnunet_pq_lib.h>
      24             : #include <taler/taler_error_codes.h>
      25             : #include <taler/taler_dbevents.h>
      26             : #include <taler/taler_pq_lib.h>
      27             : #include "pg_insert_token_family_key.h"
      28             : #include "pg_helper.h"
      29             : 
      30             : 
      31             : enum GNUNET_DB_QueryStatus
      32           4 : TMH_PG_insert_token_family_key (
      33             :   void *cls,
      34             :   const char *merchant_id,
      35             :   const char *token_family_slug,
      36             :   const struct TALER_TokenIssuePublicKey *pub,
      37             :   const struct TALER_TokenIssuePrivateKey *priv,
      38             :   struct GNUNET_TIME_Timestamp key_expires,
      39             :   struct GNUNET_TIME_Timestamp valid_after,
      40             :   struct GNUNET_TIME_Timestamp valid_before)
      41             : {
      42           4 :   struct PostgresClosure *pg = cls;
      43             :   struct GNUNET_TIME_Timestamp now
      44           4 :     = GNUNET_TIME_timestamp_get ();
      45           4 :   const char *cipher = NULL;
      46             :   struct GNUNET_HashCode pub_hash;
      47             : 
      48           4 :   switch (pub->public_key->cipher)
      49             :   {
      50           4 :   case GNUNET_CRYPTO_BSA_RSA:
      51           4 :     cipher = "rsa";
      52           4 :     GNUNET_CRYPTO_rsa_public_key_hash (
      53           4 :       pub->public_key->details.rsa_public_key,
      54             :       &pub_hash);
      55           4 :     break;
      56           0 :   case GNUNET_CRYPTO_BSA_CS:
      57           0 :     cipher = "cs";
      58           0 :     GNUNET_CRYPTO_hash (
      59           0 :       &pub->public_key->details.cs_public_key,
      60             :       sizeof (pub->public_key->details.cs_public_key),
      61             :       &pub_hash);
      62           0 :     break;
      63           0 :   case GNUNET_CRYPTO_BSA_INVALID:
      64           0 :     GNUNET_break (0);
      65           0 :     return GNUNET_DB_STATUS_HARD_ERROR;
      66             :   }
      67           4 :   GNUNET_assert (pub->public_key->cipher ==
      68             :                  priv->private_key->cipher);
      69           4 :   GNUNET_assert (0 ==
      70             :                  GNUNET_memcmp (&pub_hash,
      71             :                                 &pub->public_key->pub_key_hash));
      72           4 :   GNUNET_assert (! GNUNET_TIME_absolute_is_zero (
      73             :                    valid_after.abs_time));
      74           4 :   GNUNET_assert (! GNUNET_TIME_absolute_is_zero (
      75             :                    valid_before.abs_time));
      76           4 :   PREPARE (pg,
      77             :            "token_family_key_insert",
      78             :            "INSERT INTO merchant_token_family_keys "
      79             :            "(token_family_serial"
      80             :            ",pub"
      81             :            ",h_pub"
      82             :            ",priv"
      83             :            ",private_key_created_at"
      84             :            ",private_key_deleted_at"
      85             :            ",signature_validity_start"
      86             :            ",signature_validity_end"
      87             :            ",cipher)"
      88             :            " SELECT token_family_serial, $2, $3, $4, $5, $6, $7, $8, $9"
      89             :            " FROM merchant_token_families"
      90             :            " WHERE (slug = $1)"
      91             :            "   AND merchant_serial="
      92             :            "   (SELECT merchant_serial"
      93             :            "      FROM merchant_instances"
      94             :            "     WHERE merchant_id=$10)");
      95             :   {
      96           4 :     struct GNUNET_PQ_QueryParam params[] = {
      97           4 :       GNUNET_PQ_query_param_string (token_family_slug),
      98           4 :       GNUNET_PQ_query_param_blind_sign_pub (pub->public_key),
      99           4 :       GNUNET_PQ_query_param_auto_from_type (&pub->public_key->pub_key_hash),
     100           4 :       GNUNET_PQ_query_param_blind_sign_priv (priv->private_key),
     101           4 :       GNUNET_PQ_query_param_timestamp (&now),
     102           4 :       GNUNET_PQ_query_param_timestamp (&key_expires),
     103           4 :       GNUNET_PQ_query_param_timestamp (&valid_after),
     104           4 :       GNUNET_PQ_query_param_timestamp (&valid_before),
     105           4 :       GNUNET_PQ_query_param_string (cipher),
     106           4 :       GNUNET_PQ_query_param_string (merchant_id),
     107             :       GNUNET_PQ_query_param_end
     108             :     };
     109             :     enum GNUNET_DB_QueryStatus qs;
     110             : 
     111           4 :     qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
     112             :                                              "token_family_key_insert",
     113             :                                              params);
     114           4 :     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     115             :                 "Insert into MTFK %s with valid [%llu,%llu] got %d\n",
     116             :                 token_family_slug,
     117             :                 (unsigned long long) valid_after.abs_time.abs_value_us,
     118             :                 (unsigned long long) valid_before.abs_time.abs_value_us,
     119             :                 (int) qs);
     120           4 :     return qs;
     121             :   }
     122             : }

Generated by: LCOV version 1.16