gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: add json helper for parsing blinded sign


From: gnunet
Subject: [gnunet] branch master updated: add json helper for parsing blinded signatures
Date: Sat, 11 May 2024 16:00:20 +0200

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

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

The following commit(s) were added to refs/heads/master by this push:
     new 450d05caf add json helper for parsing blinded signatures
450d05caf is described below

commit 450d05cafa9235568463ad28ce833b5126bb9866
Author: Christian Blättler <blatc2@bfh.ch>
AuthorDate: Sat May 11 15:55:52 2024 +0200

    add json helper for parsing blinded signatures
---
 src/include/gnunet_json_lib.h |  11 ++++
 src/lib/json/json_helper.c    | 131 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 142 insertions(+)

diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h
index ae0e10b78..2059e127f 100644
--- a/src/include/gnunet_json_lib.h
+++ b/src/include/gnunet_json_lib.h
@@ -441,6 +441,17 @@ GNUNET_JSON_spec_blinded_message (const char *name,
                                   struct GNUNET_CRYPTO_BlindedMessage **msg);
 
 
+/**
+ * Specification for parsing a blinded signature.
+ *
+ * @param name name of the JSON field
+ * @param sig where to store the blinded signature found under @a name
+ */
+struct GNUNET_JSON_Specification
+GNUNET_JSON_spec_blinded_signature (const char *field,
+                                    struct GNUNET_CRYPTO_BlindedSignature 
**b_sig);
+
+
 /**
  * Specification for parsing a unblinded signature.
  *
diff --git a/src/lib/json/json_helper.c b/src/lib/json/json_helper.c
index dfe4ad025..5c2f8ae05 100644
--- a/src/lib/json/json_helper.c
+++ b/src/lib/json/json_helper.c
@@ -1344,6 +1344,137 @@ GNUNET_JSON_spec_blinded_message (const char *name,
 }
 
 
+/**
+ * Parse given JSON object to a blinded 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_sig (void *cls,
+                   json_t *root,
+                   struct GNUNET_JSON_Specification *spec)
+{
+  struct GNUNET_CRYPTO_BlindedSignature **target = 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;
+      }
+      *target = 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;
+      }
+      *target = blinded_sig;
+      return GNUNET_OK;
+    }
+  }
+  GNUNET_break_op (0);
+  GNUNET_free (blinded_sig);
+  return GNUNET_SYSERR;
+}
+
+
+/**
+ * Cleanup data left from parsing blinded sig.
+ *
+ * @param cls closure, NULL
+ * @param[out] spec where to free the data
+ */
+static void
+clean_blinded_sig (void *cls,
+                   struct GNUNET_JSON_Specification *spec)
+{
+  struct GNUNET_CRYPTO_BlindedSignature **b_sig = spec->ptr;
+
+  (void) cls;
+
+  if (NULL != *b_sig)
+  {
+    GNUNET_CRYPTO_blinded_sig_decref (*b_sig);
+    *b_sig = NULL;
+  }
+}
+
+
+struct GNUNET_JSON_Specification
+GNUNET_JSON_spec_blinded_signature (const char *field,
+                                    struct GNUNET_CRYPTO_BlindedSignature 
**b_sig)
+{
+  struct GNUNET_JSON_Specification ret = {
+    .parser = &parse_blinded_sig,
+    .cleaner = &clean_blinded_sig,
+    .field = field,
+    .ptr = b_sig
+  };
+
+  *b_sig = NULL;
+  return ret;
+}
+
 /**
  * Parse given JSON object to unblinded signature.
  *

-- 
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]