From 9f4707bfc88206ab8cc38869950211f9e3883de7 Mon Sep 17 00:00:00 2001 From: Kyle Den Hartog Date: Fri, 11 Jan 2019 16:09:31 -0700 Subject: [PATCH] changed from message pack encoding to base64 encoding Signed-off-by: Kyle Den Hartog --- libindy/src/domain/crypto/combo_box.rs | 12 --------- libindy/src/services/crypto/mod.rs | 35 +++++++++++++++++++++----- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/libindy/src/domain/crypto/combo_box.rs b/libindy/src/domain/crypto/combo_box.rs index 1bf3656eea..c4ccce9174 100644 --- a/libindy/src/domain/crypto/combo_box.rs +++ b/libindy/src/domain/crypto/combo_box.rs @@ -1,18 +1,6 @@ -extern crate rmp_serde; - #[derive(Serialize, Deserialize, Debug)] pub struct ComboBox { pub msg: String, pub sender: String, pub nonce: String } - -impl ComboBox { - pub fn to_msg_pack(&self) -> Result, rmp_serde::encode::Error> { - rmp_serde::encode::to_vec_named(self) - } - - pub fn from_msg_pack(bytes: &[u8]) -> Result { - rmp_serde::decode::from_slice(bytes) - } -} \ No newline at end of file diff --git a/libindy/src/services/crypto/mod.rs b/libindy/src/services/crypto/mod.rs index bada53cd5c..cd456326b6 100644 --- a/libindy/src/services/crypto/mod.rs +++ b/libindy/src/services/crypto/mod.rs @@ -344,10 +344,16 @@ impl CryptoService { }; //TODO check about removing msg_pack dependency - let msg_pack = combo_box.to_msg_pack() - .map_err(|e| CommonError::InvalidState(format!("Can't serialize ComboBox: {:?}", e)))?; - - let res = self.crypto_box_seal(&their_vk, &msg_pack)?; + let combo_box_str = serde_json::to_string(&combo_box) + .map_err(|err| + CryptoError::CommonError( + CommonError::InvalidStructure( + format!("Failed to encode combo_box {}", err) + ) + ) + )?; + let combo_box_encoded = base64::encode(combo_box_str.as_bytes()); + let res = self.crypto_box_seal(&their_vk, combo_box_encoded.as_bytes())?; Ok(res) } @@ -355,8 +361,25 @@ impl CryptoService { pub fn authenticated_decrypt(&self, my_key: &Key, doc: &[u8]) -> Result<(String, Vec), CryptoError> { let decrypted_msg = self.crypto_box_seal_open(&my_key, &doc)?; - let parsed_msg = ComboBox::from_msg_pack(decrypted_msg.as_slice()) - .map_err(|err| CommonError::InvalidStructure(format!("Can't deserialize ComboBox: {:?}", err)))?; + let combo_box_encoded_str = String::from_utf8(decrypted_msg) + .map_err(|err| + CryptoError::CommonError( + CommonError::InvalidStructure( + format!("failed to decode combo_box to utf-8 {}", err) + ) + ) + )?; + let combo_box_decoded = base64::decode(&combo_box_encoded_str) + .map_err(|err| CryptoError::CommonError(err))?; + + let parsed_msg : ComboBox = serde_json::from_slice(combo_box_decoded.as_slice()) + .map_err(|err| + CryptoError::CommonError( + CommonError::InvalidStructure( + format!("Failed to serialize combo_box {}", err) + ) + ) + )?; let doc: Vec = base64::decode(&parsed_msg.msg) .map_err(|err| CommonError::InvalidStructure(format!("Can't decode internal msg filed from base64 {}", err)))?;