gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: avoid unnecessary base32-encodi


From: gnunet
Subject: [taler-anastasis] branch master updated: avoid unnecessary base32-encoding core secret, fix test
Date: Tue, 13 Jul 2021 12:26:29 +0200

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

grothoff pushed a commit to branch master
in repository anastasis.

The following commit(s) were added to refs/heads/master by this push:
     new 78eaac4  avoid unnecessary base32-encoding core secret, fix test
78eaac4 is described below

commit 78eaac4c8c22281fef34e537354acd2bb1669460
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Tue Jul 13 07:55:53 2021 +0200

    avoid unnecessary base32-encoding core secret, fix test
---
 src/cli/test_anastasis_reducer_enter_secret.sh | 12 ++--
 src/reducer/anastasis_api_backup_redux.c       | 84 ++++++++++++++------------
 2 files changed, 52 insertions(+), 44 deletions(-)

diff --git a/src/cli/test_anastasis_reducer_enter_secret.sh 
b/src/cli/test_anastasis_reducer_enter_secret.sh
index 372a3c6..dadd8d0 100755
--- a/src/cli/test_anastasis_reducer_enter_secret.sh
+++ b/src/cli/test_anastasis_reducer_enter_secret.sh
@@ -278,7 +278,7 @@ $PREFIX anastasis-reducer -a \
 STATE=`jq -r -e .backup_state < $TFILE`
 if test "$STATE" != "SECRET_EDITING"
 then
-    jq < $TFILE
+    jq -e . $TFILE
     exit_fail "Expected new state to be 'SECRET_EDITING', got '$STATE'"
 fi
 
@@ -299,16 +299,16 @@ $PREFIX anastasis-reducer -a \
 STATE=`jq -r -e .backup_state < $UFILE`
 if test "$STATE" != "SECRET_EDITING"
 then
-    jq < $UFILE
+    jq -e . $UFILE
     exit_fail "Expected new state to be 'SECRET_EDITING', got '$STATE'"
 fi
 
-FEES=`jq -r -e '.upload_fees[0]' < $UFILE`
+FEES=`jq -r -e '.upload_fees[0].fee' < $UFILE`
 # 4x 4.99 for annual fees, plus 4x0.01 for truth uploads
 if test "$FEES" != "TESTKUDOS:20"
 then
-    jq < $TFILE
-    exit_fail "Expected upload fees to be 'TESTKUDOS:19.96', got '$FEES'"
+    jq -e . $TFILE
+    exit_fail "Expected upload fees to be 'TESTKUDOS:20', got '$FEES'"
 fi
 
 
@@ -320,7 +320,7 @@ $PREFIX anastasis-reducer next $UFILE $TFILE
 STATE=`jq -r -e .backup_state < $TFILE`
 if test "$STATE" != "TRUTHS_PAYING"
 then
-    jq < $TFILE
+    jq -e . $TFILE
     exit_fail "Expected new state to be 'TRUTHS_PAYING', got '$STATE'"
 fi
 
diff --git a/src/reducer/anastasis_api_backup_redux.c 
b/src/reducer/anastasis_api_backup_redux.c
index 78c5be9..ce48268 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -2931,8 +2931,7 @@ static void
 share_secret (struct UploadContext *uc)
 {
   json_t *user_id;
-  size_t core_secret_size;
-  void *core_secret;
+  json_t *core_secret;
   json_t *jpolicies;
   json_t *providers = NULL;
   size_t policies_len;
@@ -2945,9 +2944,8 @@ share_secret (struct UploadContext *uc)
                            &jpolicies),
     GNUNET_JSON_spec_json ("policy_providers",
                            &providers),
-    GNUNET_JSON_spec_varsize ("core_secret",
-                              &core_secret,
-                              &core_secret_size),
+    GNUNET_JSON_spec_json ("core_secret",
+                           &core_secret),
     GNUNET_JSON_spec_end ()
   };
 
@@ -3200,18 +3198,28 @@ share_secret (struct UploadContext *uc)
       }
     }
 
-    uc->ss = ANASTASIS_secret_share (ANASTASIS_REDUX_ctx_,
-                                     user_id,
-                                     pds,
-                                     pds_len,
-                                     policies,
-                                     policies_len,
-                                     uc->years,
-                                     timeout,
-                                     &secret_share_result_cb,
-                                     uc,
-                                     core_secret,
-                                     core_secret_size);
+    {
+      char *secret;
+      size_t secret_size;
+
+      secret = json_dumps (core_secret,
+                           JSON_COMPACT | JSON_SORT_KEYS);
+      GNUNET_assert (NULL != secret);
+      secret_size = strlen (secret);
+      uc->ss = ANASTASIS_secret_share (ANASTASIS_REDUX_ctx_,
+                                       user_id,
+                                       pds,
+                                       pds_len,
+                                       policies,
+                                       policies_len,
+                                       uc->years,
+                                       timeout,
+                                       &secret_share_result_cb,
+                                       uc,
+                                       secret,
+                                       secret_size);
+      GNUNET_free (secret);
+    }
     for (unsigned int i = 0; i<policies_len; i++)
       ANASTASIS_policy_destroy (vpolicies[i]);
   }
@@ -3969,20 +3977,31 @@ core_secret_fits (const json_t *state,
  * Check if the upload size limit is satisfied.
  *
  * @param state our state
- * @param secret_size size of the uploaded secret
+ * @param jsecret the uploaded secret
  * @return #GNUNET_OK if @a secret_size works for all providers,
  *     #GNUNET_NO if the @a secret_size is too big,
  *     #GNUNET_SYSERR if a provider has a limit of 0
  */
 static enum GNUNET_GenericReturnValue
 check_upload_size_limit (json_t *state,
-                         size_t secret_size)
+                         const json_t *jsecret)
 {
   uint32_t min_limit = UINT32_MAX;
   json_t *aps = json_object_get (state,
                                  "authentication_providers");
   const char *url;
   json_t *ap;
+  size_t secret_size;
+
+  {
+    char *secret;
+
+    secret = json_dumps (jsecret,
+                         JSON_COMPACT | JSON_SORT_KEYS);
+    GNUNET_assert (NULL != secret);
+    secret_size = strlen (secret);
+    GNUNET_free (secret);
+  }
 
   /* We calculate the minimum upload limit of all possible providers;
      this is under the (simplified) assumption that we store the
@@ -4035,8 +4054,6 @@ enter_secret (json_t *state,
               void *cb_cls)
 {
   json_t *jsecret;
-  void *secret;
-  size_t secret_size;
   const char *secret_name = NULL;
   struct GNUNET_TIME_Absolute expiration = {0};
   struct GNUNET_JSON_Specification spec[] = {
@@ -4070,17 +4087,13 @@ enter_secret (json_t *state,
                            "'secret' argument required");
     return NULL;
   }
-  secret = json_dumps (jsecret,
-                       JSON_COMPACT | JSON_SORT_KEYS);
-  GNUNET_assert (NULL != secret);
-  secret_size = strlen (secret);
 
   /* check upload size limit */
   {
     enum GNUNET_GenericReturnValue ret;
 
     ret = check_upload_size_limit (state,
-                                   secret_size);
+                                   jsecret);
     switch (ret)
     {
     case GNUNET_SYSERR:
@@ -4088,14 +4101,12 @@ enter_secret (json_t *state,
                              cb_cls,
                              TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
                              "provider has an upload limit of 0");
-      GNUNET_free (secret);
       return NULL;
     case GNUNET_NO:
       ANASTASIS_redux_fail_ (cb,
                              cb_cls,
                              TALER_EC_ANASTASIS_REDUCER_SECRET_TOO_BIG,
                              NULL);
-      GNUNET_free (secret);
       return NULL;
     default:
       break;
@@ -4120,10 +4131,9 @@ enter_secret (json_t *state,
                                         "secret_name",
                                         json_string (secret_name)));
   GNUNET_assert (0 ==
-                 json_object_set_new (state,
-                                      "core_secret",
-                                      GNUNET_JSON_from_data (secret,
-                                                             secret_size)));
+                 json_object_set (state,
+                                  "core_secret",
+                                  jsecret));
   cb (cb_cls,
       TALER_EC_NONE,
       state);
@@ -4212,12 +4222,10 @@ finish_secret (json_t *state,
                ANASTASIS_ActionCallback cb,
                void *cb_cls)
 {
-  void *core_secret;
-  size_t core_secret_size;
+  json_t *core_secret;
   struct GNUNET_JSON_Specification spec[] = {
-    GNUNET_JSON_spec_varsize ("core_secret",
-                              &core_secret,
-                              &core_secret_size),
+    GNUNET_JSON_spec_json ("core_secret",
+                           &core_secret),
     GNUNET_JSON_spec_end ()
   };
 
@@ -4238,7 +4246,7 @@ finish_secret (json_t *state,
     enum GNUNET_GenericReturnValue ret;
 
     ret = check_upload_size_limit (state,
-                                   core_secret_size);
+                                   core_secret);
     switch (ret)
     {
     case GNUNET_SYSERR:

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