gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-exchange] 18/24: use new gnunet json spec functions


From: gnunet
Subject: [taler-exchange] 18/24: use new gnunet json spec functions
Date: Thu, 13 Jun 2024 17:04:08 +0200

This is an automated email from the git hooks/post-receive script.

christian-blaettler pushed a commit to branch master
in repository exchange.

commit 67ced977a3b6d39e932d53d3b4f6f16085b19745
Author: Christian Blättler <blatc2@bfh.ch>
AuthorDate: Sat May 11 15:59:55 2024 +0200

    use new gnunet json spec functions
---
 src/json/json_helper.c | 368 +------------------------------------------------
 1 file changed, 6 insertions(+), 362 deletions(-)

diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index 9870f252e..7cad6a38c 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -531,261 +531,23 @@ TALER_JSON_spec_age_commitment (const char *name,
   return ret;
 }
 
-
-/**
- * Parse given JSON object to token issue signature.
- * TODO: Exctract common code between this and parse_denom_sig function to a 
helper.
- *
- * @param cls closure, NULL
- * @param root the json object representing data
- * @param[out] spec where to write the data
- * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
- */
-static enum GNUNET_GenericReturnValue
-parse_token_issue_sig (void *cls,
-                       json_t *root,
-                       struct GNUNET_JSON_Specification *spec)
-{
-  struct TALER_TokenIssueSignatureP *issue_sig = spec->ptr;
-  struct GNUNET_CRYPTO_UnblindedSignature *unblinded_sig;
-  const char *cipher;
-  struct GNUNET_JSON_Specification dspec[] = {
-    GNUNET_JSON_spec_string ("cipher",
-                             &cipher),
-    GNUNET_JSON_spec_end ()
-  };
-  const char *emsg;
-  unsigned int eline;
-
-  (void) cls;
-  if (GNUNET_OK !=
-      GNUNET_JSON_parse (root,
-                         dspec,
-                         &emsg,
-                         &eline))
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  unblinded_sig = GNUNET_new (struct GNUNET_CRYPTO_UnblindedSignature);
-  unblinded_sig->cipher = string_to_cipher (cipher);
-  unblinded_sig->rc = 1;
-  switch (unblinded_sig->cipher)
-  {
-  case GNUNET_CRYPTO_BSA_INVALID:
-    break;
-  case GNUNET_CRYPTO_BSA_RSA:
-    {
-      struct GNUNET_JSON_Specification ispec[] = {
-        GNUNET_JSON_spec_rsa_signature (
-          "rsa_signature",
-          &unblinded_sig->details.rsa_signature),
-        GNUNET_JSON_spec_end ()
-      };
-
-      if (GNUNET_OK !=
-          GNUNET_JSON_parse (root,
-                             ispec,
-                             &emsg,
-                             &eline))
-      {
-        GNUNET_break_op (0);
-        GNUNET_free (unblinded_sig);
-        return GNUNET_SYSERR;
-      }
-      issue_sig->signature = unblinded_sig;
-      return GNUNET_OK;
-    }
-  case GNUNET_CRYPTO_BSA_CS:
-    {
-      struct GNUNET_JSON_Specification ispec[] = {
-        GNUNET_JSON_spec_fixed_auto ("cs_signature_r",
-                                     &unblinded_sig->details.cs_signature.
-                                     r_point),
-        GNUNET_JSON_spec_fixed_auto ("cs_signature_s",
-                                     &unblinded_sig->details.cs_signature.
-                                     s_scalar),
-        GNUNET_JSON_spec_end ()
-      };
-
-      if (GNUNET_OK !=
-          GNUNET_JSON_parse (root,
-                             ispec,
-                             &emsg,
-                             &eline))
-      {
-        GNUNET_break_op (0);
-        GNUNET_free (unblinded_sig);
-        return GNUNET_SYSERR;
-      }
-      issue_sig->signature = unblinded_sig;
-      return GNUNET_OK;
-    }
-  }
-  GNUNET_break_op (0);
-  GNUNET_free (unblinded_sig);
-  return GNUNET_SYSERR;
-}
-
-
-/**
- * Cleanup data left from parsing token issue signature.
- *
- * @param cls closure, NULL
- * @param[out] spec where to free the data
- */
-static void
-clean_token_issue_sig (void *cls,
-                       struct GNUNET_JSON_Specification *spec)
-{
-  struct TALER_TokenIssueSignatureP *issue_sig = spec->ptr;
-
-  (void) cls;
-  TALER_token_issue_sig_free (issue_sig);
-}
-
-
 struct GNUNET_JSON_Specification
 TALER_JSON_spec_token_issue_sig (const char *field,
                                  struct TALER_TokenIssueSignatureP *sig)
 {
-  struct GNUNET_JSON_Specification ret = {
-    .parser = &parse_token_issue_sig,
-    .cleaner = &clean_token_issue_sig,
-    .field = field,
-    .ptr = sig
-  };
-
   sig->signature = NULL;
-  return ret;
+  return GNUNET_JSON_spec_unblinded_signature (field,
+                                               &sig->signature);
 }
 
-
-/**
- * Parse given JSON object to blinded token issue signature.
- *
- * @param cls closure, NULL
- * @param root the json object representing data
- * @param[out] spec where to write the data
- * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
- */
-static enum GNUNET_GenericReturnValue
-parse_blinded_token_issue_sig (void *cls,
-                               json_t *root,
-                               struct GNUNET_JSON_Specification *spec)
-{
-  struct TALER_TokenIssueBlindSignatureP *issue_sig = spec->ptr;
-  struct GNUNET_CRYPTO_BlindedSignature *blinded_sig;
-  const char *cipher;
-  struct GNUNET_JSON_Specification dspec[] = {
-    GNUNET_JSON_spec_string ("cipher",
-                             &cipher),
-    GNUNET_JSON_spec_end ()
-  };
-  const char *emsg;
-  unsigned int eline;
-
-  (void) cls;
-  if (GNUNET_OK !=
-      GNUNET_JSON_parse (root,
-                         dspec,
-                         &emsg,
-                         &eline))
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  blinded_sig = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature);
-  blinded_sig->cipher = string_to_cipher (cipher);
-  blinded_sig->rc = 1;
-  switch (blinded_sig->cipher)
-  {
-  case GNUNET_CRYPTO_BSA_INVALID:
-    break;
-  case GNUNET_CRYPTO_BSA_RSA:
-    {
-      struct GNUNET_JSON_Specification ispec[] = {
-        GNUNET_JSON_spec_rsa_signature (
-          "blinded_rsa_signature",
-          &blinded_sig->details.blinded_rsa_signature),
-        GNUNET_JSON_spec_end ()
-      };
-
-      if (GNUNET_OK !=
-          GNUNET_JSON_parse (root,
-                             ispec,
-                             &emsg,
-                             &eline))
-      {
-        GNUNET_break_op (0);
-        GNUNET_free (blinded_sig);
-        return GNUNET_SYSERR;
-      }
-      issue_sig->signature = blinded_sig;
-      return GNUNET_OK;
-    }
-  case GNUNET_CRYPTO_BSA_CS:
-    {
-      struct GNUNET_JSON_Specification ispec[] = {
-        GNUNET_JSON_spec_uint32 ("b",
-                                 &blinded_sig->details.blinded_cs_answer.b),
-        GNUNET_JSON_spec_fixed_auto ("s",
-                                     &blinded_sig->details.blinded_cs_answer.
-                                     s_scalar),
-        GNUNET_JSON_spec_end ()
-      };
-
-      if (GNUNET_OK !=
-          GNUNET_JSON_parse (root,
-                             ispec,
-                             &emsg,
-                             &eline))
-      {
-        GNUNET_break_op (0);
-        GNUNET_free (blinded_sig);
-        return GNUNET_SYSERR;
-      }
-      issue_sig->signature = blinded_sig;
-      return GNUNET_OK;
-    }
-  }
-  GNUNET_break_op (0);
-  GNUNET_free (blinded_sig);
-  return GNUNET_SYSERR;
-}
-
-
-/**
- * Cleanup data left from parsing blinded token sisue sig.
- *
- * @param cls closure, NULL
- * @param[out] spec where to free the data
- */
-static void
-clean_blinded_token_issue_sig (void *cls,
-                               struct GNUNET_JSON_Specification *spec)
-{
-  struct TALER_TokenIssueBlindSignatureP *issue_sig = spec->ptr;
-
-  (void) cls;
-  TALER_blinded_issue_sig_free (issue_sig);
-}
-
-
 struct GNUNET_JSON_Specification
 TALER_JSON_spec_blinded_token_issue_sig (
   const char *field,
   struct TALER_TokenIssueBlindSignatureP *sig)
 {
-  struct GNUNET_JSON_Specification ret = {
-    .parser = &parse_blinded_token_issue_sig,
-    .cleaner = &clean_blinded_token_issue_sig,
-    .field = field,
-    .ptr = sig
-  };
-
   sig->signature = NULL;
-  return ret;
+  return GNUNET_JSON_spec_blinded_signature (field,
+                                             &sig->signature);
 }
 
 
@@ -1030,131 +792,13 @@ TALER_JSON_spec_denom_pub_cipher (const char *field,
 }
 
 
-/**
- * Parse given JSON object to denomination signature.
- *
- * @param cls closure, NULL
- * @param root the json object representing data
- * @param[out] spec where to write the data
- * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
- */
-static enum GNUNET_GenericReturnValue
-parse_denom_sig (void *cls,
-                 json_t *root,
-                 struct GNUNET_JSON_Specification *spec)
-{
-  struct TALER_DenominationSignature *denom_sig = spec->ptr;
-  struct GNUNET_CRYPTO_UnblindedSignature *unblinded_sig;
-  const char *cipher;
-  struct GNUNET_JSON_Specification dspec[] = {
-    GNUNET_JSON_spec_string ("cipher",
-                             &cipher),
-    GNUNET_JSON_spec_end ()
-  };
-  const char *emsg;
-  unsigned int eline;
-
-  (void) cls;
-  if (GNUNET_OK !=
-      GNUNET_JSON_parse (root,
-                         dspec,
-                         &emsg,
-                         &eline))
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  unblinded_sig = GNUNET_new (struct GNUNET_CRYPTO_UnblindedSignature);
-  unblinded_sig->cipher = string_to_cipher (cipher);
-  unblinded_sig->rc = 1;
-  switch (unblinded_sig->cipher)
-  {
-  case GNUNET_CRYPTO_BSA_INVALID:
-    break;
-  case GNUNET_CRYPTO_BSA_RSA:
-    {
-      struct GNUNET_JSON_Specification ispec[] = {
-        GNUNET_JSON_spec_rsa_signature (
-          "rsa_signature",
-          &unblinded_sig->details.rsa_signature),
-        GNUNET_JSON_spec_end ()
-      };
-
-      if (GNUNET_OK !=
-          GNUNET_JSON_parse (root,
-                             ispec,
-                             &emsg,
-                             &eline))
-      {
-        GNUNET_break_op (0);
-        GNUNET_free (unblinded_sig);
-        return GNUNET_SYSERR;
-      }
-      denom_sig->unblinded_sig = unblinded_sig;
-      return GNUNET_OK;
-    }
-  case GNUNET_CRYPTO_BSA_CS:
-    {
-      struct GNUNET_JSON_Specification ispec[] = {
-        GNUNET_JSON_spec_fixed_auto ("cs_signature_r",
-                                     &unblinded_sig->details.cs_signature.
-                                     r_point),
-        GNUNET_JSON_spec_fixed_auto ("cs_signature_s",
-                                     &unblinded_sig->details.cs_signature.
-                                     s_scalar),
-        GNUNET_JSON_spec_end ()
-      };
-
-      if (GNUNET_OK !=
-          GNUNET_JSON_parse (root,
-                             ispec,
-                             &emsg,
-                             &eline))
-      {
-        GNUNET_break_op (0);
-        GNUNET_free (unblinded_sig);
-        return GNUNET_SYSERR;
-      }
-      denom_sig->unblinded_sig = unblinded_sig;
-      return GNUNET_OK;
-    }
-  }
-  GNUNET_break_op (0);
-  GNUNET_free (unblinded_sig);
-  return GNUNET_SYSERR;
-}
-
-
-/**
- * Cleanup data left from parsing denomination public key.
- *
- * @param cls closure, NULL
- * @param[out] spec where to free the data
- */
-static void
-clean_denom_sig (void *cls,
-                 struct GNUNET_JSON_Specification *spec)
-{
-  struct TALER_DenominationSignature *denom_sig = spec->ptr;
-
-  (void) cls;
-  TALER_denom_sig_free (denom_sig);
-}
-
-
 struct GNUNET_JSON_Specification
 TALER_JSON_spec_denom_sig (const char *field,
                            struct TALER_DenominationSignature *sig)
 {
-  struct GNUNET_JSON_Specification ret = {
-    .parser = &parse_denom_sig,
-    .cleaner = &clean_denom_sig,
-    .field = field,
-    .ptr = sig
-  };
-
   sig->unblinded_sig = NULL;
-  return ret;
+  return GNUNET_JSON_spec_unblinded_signature (field,
+                                               &sig->unblinded_sig);
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]