From 950df84b67d8fa219660e747f6238e21d849c2ca Mon Sep 17 00:00:00 2001 From: danielle-tfh Date: Tue, 24 Sep 2024 16:54:29 +0200 Subject: [PATCH] Fix iris shares JSON --- iris-mpc-common/src/bin/shares_encoding.rs | 38 ++++++++++----------- iris-mpc-common/src/helpers/smpc_request.rs | 12 ++++--- iris-mpc-common/tests/smpc_request.rs | 22 ++++++------ iris-mpc/src/bin/client.rs | 11 +++--- iris-mpc/src/bin/server.rs | 8 ++--- 5 files changed, 48 insertions(+), 43 deletions(-) diff --git a/iris-mpc-common/src/bin/shares_encoding.rs b/iris-mpc-common/src/bin/shares_encoding.rs index 9484e7971..127fcf374 100644 --- a/iris-mpc-common/src/bin/shares_encoding.rs +++ b/iris-mpc-common/src/bin/shares_encoding.rs @@ -31,13 +31,13 @@ fn sorted_keys(value: &T, serializer: S) -> Result< #[derive(Serialize, Debug, Clone, PartialEq)] struct IrisCodeSharesJson { #[serde(rename = "IRIS_version")] - iris_version: String, + iris_version: String, #[serde(rename = "IRIS_shares_version")] - iris_shares_version: String, - left_iris_code_shares: String, - left_iris_mask_shares: String, - right_iris_code_shares: String, - right_iris_mask_shares: String, + iris_shares_version: String, + left_iris_code_share: String, + left_mask_code_share: String, + right_iris_code_share: String, + right_mask_code_share: String, } /// Iris code shares. @@ -109,12 +109,12 @@ fn main() { .enumerate() { let iris_code_shares = IrisCodeSharesJson { - iris_version: IRIS_VERSION.to_string(), - iris_shares_version: IRIS_MPC_VERSION.to_string(), - left_iris_code_shares: li.clone(), - left_iris_mask_shares: lm.clone(), - right_iris_code_shares: ri.clone(), - right_iris_mask_shares: rm.clone(), + iris_version: IRIS_VERSION.to_string(), + iris_shares_version: IRIS_MPC_VERSION.to_string(), + left_iris_code_share: li.clone(), + left_mask_code_share: lm.clone(), + right_iris_code_share: ri.clone(), + right_mask_code_share: rm.clone(), }; let json_u8 = serde_json::to_string(&SerializeWithSortedKeys(&iris_code_shares)) .unwrap() @@ -144,15 +144,15 @@ mod tests { #[test] fn test_iris_code_shares_json() { let iris_code_shares = IrisCodeSharesJson { - iris_version: IRIS_VERSION.to_string(), - iris_shares_version: IRIS_MPC_VERSION.to_string(), - left_iris_code_shares: "left_iris_code_shares".to_string(), - left_iris_mask_shares: "left_iris_mask_shares".to_string(), - right_iris_code_shares: "right_iris_code_shares".to_string(), - right_iris_mask_shares: "right_iris_mask_shares".to_string(), + iris_version: IRIS_VERSION.to_string(), + iris_shares_version: IRIS_MPC_VERSION.to_string(), + left_iris_code_share: "left_iris_code_share".to_string(), + left_mask_code_share: "left_mask_code_share".to_string(), + right_iris_code_share: "right_iris_code_share".to_string(), + right_mask_code_share: "right_mask_code_share".to_string(), }; - let expected = r#"{"IRIS_shares_version":"1.0","IRIS_version":"1.1","left_iris_code_shares":"left_iris_code_shares","left_iris_mask_shares":"left_iris_mask_shares","right_iris_code_shares":"right_iris_code_shares","right_iris_mask_shares":"right_iris_mask_shares"}"#; + let expected = r#"{"IRIS_shares_version":"1.0","IRIS_version":"1.1","left_iris_code_share":"left_iris_code_share","left_mask_code_share":"left_mask_code_share","right_iris_code_share":"right_iris_code_share","right_mask_code_share":"right_mask_code_share"}"#; assert_eq!( serde_json::to_string(&SerializeWithSortedKeys(&iris_code_shares)).unwrap(), expected diff --git a/iris-mpc-common/src/helpers/smpc_request.rs b/iris-mpc-common/src/helpers/smpc_request.rs index 199bb2f42..c2f1e3966 100644 --- a/iris-mpc-common/src/helpers/smpc_request.rs +++ b/iris-mpc-common/src/helpers/smpc_request.rs @@ -171,11 +171,13 @@ pub struct SharesS3Object { #[derive(PartialEq, Serialize, Deserialize, Debug, Clone)] pub struct IrisCodesJSON { #[serde(rename = "IRIS_version")] - pub iris_version: String, - pub left_iris_code_shares: String, // these are base64 encoded strings - pub right_iris_code_shares: String, // these are base64 encoded strings - pub left_iris_mask_shares: String, // these are base64 encoded strings - pub right_iris_mask_shares: String, // these are base64 encoded strings + pub iris_version: String, + #[serde(rename = "IRIS_shares_version")] + pub iris_shares_version: String, + pub left_iris_code_share: String, // these are base64 encoded strings + pub right_iris_code_share: String, // these are base64 encoded strings + pub left_mask_code_share: String, // these are base64 encoded strings + pub right_mask_code_share: String, // these are base64 encoded strings } impl SharesS3Object { diff --git a/iris-mpc-common/tests/smpc_request.rs b/iris-mpc-common/tests/smpc_request.rs index ab0f12090..691b1ec81 100644 --- a/iris-mpc-common/tests/smpc_request.rs +++ b/iris-mpc-common/tests/smpc_request.rs @@ -32,11 +32,12 @@ mod tests { fn mock_iris_codes_json() -> IrisCodesJSON { IrisCodesJSON { - iris_version: "1.0".to_string(), - left_iris_code_shares: STANDARD.encode("left_iris_code_mock"), - right_iris_code_shares: STANDARD.encode("right_iris_code_mock"), - left_iris_mask_shares: STANDARD.encode("left_iris_mask_mock"), - right_iris_mask_shares: STANDARD.encode("right_iris_mask_mock"), + iris_version: "1.0".to_string(), + iris_shares_version: "1.3".to_string(), + left_iris_code_share: STANDARD.encode("left_iris_code_mock"), + right_iris_code_share: STANDARD.encode("right_iris_code_mock"), + left_mask_code_share: STANDARD.encode("left_iris_mask_mock"), + right_mask_code_share: STANDARD.encode("right_iris_mask_mock"), } } @@ -102,11 +103,12 @@ mod tests { async fn test_decrypt_iris_share_success() { // Mocked base64 encoded JSON string let iris_codes_json = IrisCodesJSON { - iris_version: "1.0".to_string(), - left_iris_code_shares: "left_code".to_string(), - right_iris_code_shares: "right_code".to_string(), - left_iris_mask_shares: "left_mask".to_string(), - right_iris_mask_shares: "right_mask".to_string(), + iris_version: "1.0".to_string(), + iris_shares_version: "1.3".to_string(), + left_iris_code_share: "left_code".to_string(), + right_iris_code_share: "right_code".to_string(), + left_mask_code_share: "left_mask".to_string(), + right_mask_code_share: "right_mask".to_string(), }; let decoded_public_key = STANDARD.decode(CURRENT_PUBLIC_KEY.as_bytes()).unwrap(); diff --git a/iris-mpc/src/bin/client.rs b/iris-mpc/src/bin/client.rs index 783692802..84e7bdebe 100644 --- a/iris-mpc/src/bin/client.rs +++ b/iris-mpc/src/bin/client.rs @@ -329,11 +329,12 @@ async fn main() -> eyre::Result<()> { for i in 0..3 { let iris_codes_json = IrisCodesJSON { - iris_version: "1.0".to_string(), - right_iris_code_shares: shared_code[i].to_base64(), - right_iris_mask_shares: shared_mask[i].to_base64(), - left_iris_code_shares: shared_code[i].to_base64(), - left_iris_mask_shares: shared_mask[i].to_base64(), + iris_version: "1.0".to_string(), + iris_shares_version: "1.3".to_string(), + right_iris_code_share: shared_code[i].to_base64(), + right_mask_code_share: shared_mask[i].to_base64(), + left_iris_code_share: shared_code[i].to_base64(), + left_mask_code_share: shared_mask[i].to_base64(), }; let serialized_iris_codes_json = to_string(&iris_codes_json) .expect("Serialization failed") diff --git a/iris-mpc/src/bin/server.rs b/iris-mpc/src/bin/server.rs index f7b0cf341..19a7dc0dd 100644 --- a/iris-mpc/src/bin/server.rs +++ b/iris-mpc/src/bin/server.rs @@ -257,13 +257,13 @@ async fn receive_batch( } let (left_code, left_mask) = decode_iris_message_shares( - iris_message_share.left_iris_code_shares, - iris_message_share.left_iris_mask_shares, + iris_message_share.left_iris_code_share, + iris_message_share.left_mask_code_share, )?; let (right_code, right_mask) = decode_iris_message_shares( - iris_message_share.right_iris_code_shares, - iris_message_share.right_iris_mask_shares, + iris_message_share.right_iris_code_share, + iris_message_share.right_mask_code_share, )?; // Preprocess shares for left eye.