-add serialization
authorSchanzenbach, Martin <mschanzenbach@posteo.de>
Sat, 8 Jul 2017 18:14:49 +0000 (20:14 +0200)
committerSchanzenbach, Martin <mschanzenbach@posteo.de>
Sat, 8 Jul 2017 18:14:49 +0000 (20:14 +0200)
src/include/gnunet_crypto_lib.h
src/util/crypto_abe.c

index 6f2870c3725a599a830d1bf7d53f6cfe200acf04..8a2763894f187fd497f4f1f77d0f16ae3aab2a53 100644 (file)
@@ -2185,7 +2185,21 @@ GNUNET_CRYPTO_cpabe_decrypt (const void *block,
                              const struct GNUNET_CRYPTO_AbeKey *key,
                              void **result);
 
+ssize_t
+GNUNET_CRYPTO_cpabe_serialize_key (struct GNUNET_CRYPTO_AbeKey *key,
+                                   void **result);
+
+struct GNUNET_CRYPTO_AbeKey*
+GNUNET_CRYPTO_cpabe_deserialize_key (void *data,
+                                     size_t len);
+
+ssize_t
+GNUNET_CRYPTO_cpabe_serialize_master_key (struct GNUNET_CRYPTO_AbeMasterKey *key,
+                                          void **result);
 
+struct GNUNET_CRYPTO_AbeMasterKey*
+GNUNET_CRYPTO_cpabe_deserialize_master_key (void *data,
+                                            size_t len);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */
index d004220d1ed9c47590904f15b3a74b3020a7ea2e..62b9b71085693208f86bd30608721b052c4fea19 100644 (file)
@@ -303,3 +303,51 @@ GNUNET_CRYPTO_cpabe_decrypt (const void *block,
   
   return pt_size;
 }
+
+ssize_t
+GNUNET_CRYPTO_cpabe_serialize_key (struct GNUNET_CRYPTO_AbeKey *key,
+                                   void **result)
+{
+  ssize_t len;
+
+  len = key->pub->len + key->prv->len + 12;
+  write_cpabe (result, key->pub, len, key->prv);
+
+  return len;
+}
+
+struct GNUNET_CRYPTO_AbeKey*
+GNUNET_CRYPTO_cpabe_deserialize_key (void *data,
+                                     size_t len)
+{
+  struct GNUNET_CRYPTO_AbeKey *key;
+
+  key = GNUNET_new (struct GNUNET_CRYPTO_AbeKey);
+  read_cpabe (data, &key->pub, &key->prv);
+
+  return key;
+}
+
+ssize_t
+GNUNET_CRYPTO_cpabe_serialize_master_key (struct GNUNET_CRYPTO_AbeMasterKey *key,
+                                          void **result)
+{
+  ssize_t len;
+
+  len = key->pub->len + key->msk->len + 12;
+  write_cpabe (result, key->pub, len, key->msk);
+
+  return len;
+}
+
+struct GNUNET_CRYPTO_AbeMasterKey*
+GNUNET_CRYPTO_cpabe_deserialize_master_key (void *data,
+                                            size_t len)
+{
+  struct GNUNET_CRYPTO_AbeMasterKey *key;
+
+  key = GNUNET_new (struct GNUNET_CRYPTO_AbeMasterKey);
+  read_cpabe (data, &key->pub, &key->msk);
+
+  return key;
+}