donau

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

qr.c (2286B)


      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 qr.c
     18  * @brief Utility functions for donation statement QR Code
     19  * @author Lukas Matyja
     20  */
     21 #include "donau_config.h"
     22 #include <taler/taler_util.h>
     23 #include "donau_util.h"
     24 #include "donau_service.h"
     25 
     26 
     27 // FIXME: remove public key, only needed for testing.
     28 // The verification app should get the public key directly from the Donau.
     29 char *
     30 DONAU_generate_qr_string (
     31   const struct DONAU_DonauPublicKeyP *pub_key,
     32   const struct DONAU_DonationStatement *donation_statement)
     33 {
     34   /* The string will be structured as follows: YEAR/TOTALAMOUNT/TAXID/TAXIDSALT/ED25519SIGNATURE/PUBKEY */
     35   char *end_sig;
     36   char *end_pub;
     37   char sig_str[sizeof (struct DONAU_DonauSignatureP) * 2];
     38   char pub_str[sizeof (struct DONAU_DonauPublicKeyP) * 2];
     39   char *qr_string;
     40 
     41   end_sig = GNUNET_STRINGS_data_to_string (
     42     &donation_statement->donation_statement_sig,
     43     sizeof (struct DONAU_DonauSignatureP),
     44     sig_str,
     45     sizeof (sig_str));
     46   *end_sig = '\0';
     47   end_pub = GNUNET_STRINGS_data_to_string (
     48     pub_key,
     49     sizeof (struct DONAU_DonauPublicKeyP),
     50     pub_str,
     51     sizeof (pub_str));
     52   *end_pub = '\0';
     53   /* FIXME: escape donor_tax_id, as it might contain / or
     54      other characters that are not safe here... */
     55   GNUNET_asprintf (&qr_string,
     56                    "%u/%s/%s/%s/%s/%s",
     57                    (unsigned int) donation_statement->year,
     58                    TALER_amount2s (&donation_statement->total_amount),
     59                    donation_statement->donor_tax_id,
     60                    donation_statement->salt,
     61                    sig_str,
     62                    pub_str);
     63   return qr_string;
     64 }