Browse Source

Added serialization/deserialization for check_blockage and trust_promotion

onyinyang 2 years ago
parent
commit
67f2a708d4
2 changed files with 14 additions and 2 deletions
  1. 7 1
      src/proto/check_blockage.rs
  2. 7 1
      src/proto/trust_promotion.rs

+ 7 - 1
src/proto/check_blockage.rs

@@ -37,6 +37,9 @@ use zkp::CompactProof;
 use zkp::ProofError;
 use zkp::Transcript;
 
+use serde::{Serialize,Deserialize};
+use serde_with::serde_as;
+
 use std::collections::HashMap;
 
 use super::super::cred;
@@ -50,6 +53,7 @@ use super::super::{CMZ_A, CMZ_A_TABLE, CMZ_B, CMZ_B_TABLE};
 /// perform this protocol.
 pub const MIN_TRUST_LEVEL: u32 = 3;
 
+#[derive(Serialize, Deserialize)]
 pub struct Request {
     // Fields for blind showing the Lox credential
     P: RistrettoPoint,
@@ -78,7 +82,8 @@ pub struct State {
     bucket: Scalar,
 }
 
-#[derive(Debug)]
+#[serde_as]
+#[derive(Serialize, Deserialize, Debug)]
 pub struct Response {
     // The encrypted MAC for the Migration Key credential
     Pk: RistrettoPoint,
@@ -87,6 +92,7 @@ pub struct Response {
     // A table of encrypted Migration credentials; the encryption keys
     // are formed from the possible values of Qk (the decrypted form of
     // EncQk)
+   #[serde_as(as = "Vec<(_,[_; migration_table::ENC_MIGRATION_BYTES])>")]
     enc_migration_table: HashMap<[u8; 16], [u8; migration_table::ENC_MIGRATION_BYTES]>,
 }
 

+ 7 - 1
src/proto/trust_promotion.rs

@@ -36,6 +36,9 @@ use zkp::CompactProof;
 use zkp::ProofError;
 use zkp::Transcript;
 
+use serde::{Serialize, Deserialize};
+use serde_with::serde_as;
+
 use std::collections::HashMap;
 
 use super::super::cred;
@@ -54,6 +57,7 @@ use super::super::{CMZ_A, CMZ_A_TABLE, CMZ_B, CMZ_B_TABLE};
 /// with the system in order to move up trust levels.
 pub const UNTRUSTED_INTERVAL: u32 = 30;
 
+#[derive(Serialize, Deserialize)]
 pub struct Request {
     // Fields for blind showing the Lox credential
     // We don't need to include trust_level, invites_remaining, or
@@ -101,7 +105,8 @@ pub struct State {
     bucket: Scalar,
 }
 
-#[derive(Debug)]
+#[serde_as]
+#[derive(Serialize, Deserialize, Debug)]
 pub struct Response {
     // The encrypted MAC for the Migration Key credential
     Pk: RistrettoPoint,
@@ -110,6 +115,7 @@ pub struct Response {
     // A table of encrypted Migration credentials; the encryption keys
     // are formed from the possible values of Qk (the decrypted form of
     // EncQk)
+    #[serde_as(as = "Vec<(_,[_; migration_table::ENC_MIGRATION_BYTES])>")]
     enc_migration_table: HashMap<[u8; 16], [u8; migration_table::ENC_MIGRATION_BYTES]>,
 }