diff --git a/nucypher-core/src/message_kit.rs b/nucypher-core/src/message_kit.rs index b6e24254..5d40b9ef 100644 --- a/nucypher-core/src/message_kit.rs +++ b/nucypher-core/src/message_kit.rs @@ -67,13 +67,20 @@ impl MessageKit { } } +#[derive(Deserialize)] +struct MessageKit0 { + capsule: Capsule, + #[serde(with = "serde_bytes::as_base64")] + ciphertext: Box<[u8]>, +} + impl<'a> ProtocolObjectInner<'a> for MessageKit { fn brand() -> [u8; 4] { *b"MKit" } fn version() -> (u16, u16) { - (1, 0) + (1, 1) } fn unversioned_to_bytes(&self) -> Box<[u8]> { @@ -81,10 +88,17 @@ impl<'a> ProtocolObjectInner<'a> for MessageKit { } fn unversioned_from_bytes(minor_version: u16, bytes: &[u8]) -> Option> { - if minor_version == 0 { - Some(messagepack_deserialize(bytes)) - } else { - None + match minor_version { + 0 => { + let mkit = messagepack_deserialize::(bytes).map(|mkit| MessageKit { + capsule: mkit.capsule, + ciphertext: mkit.ciphertext, + conditions: None, + }); + Some(mkit) + } + 1 => Some(messagepack_deserialize(bytes)), + _ => None, } } } diff --git a/nucypher-core/src/reencryption.rs b/nucypher-core/src/reencryption.rs index 6d0fc46a..45235608 100644 --- a/nucypher-core/src/reencryption.rs +++ b/nucypher-core/src/reencryption.rs @@ -57,13 +57,22 @@ impl ReencryptionRequest { } } +#[derive(Deserialize)] +struct ReencryptionRequest0 { + capsules: Box<[Capsule]>, + hrac: HRAC, + encrypted_kfrag: EncryptedKeyFrag, + publisher_verifying_key: PublicKey, + bob_verifying_key: PublicKey, +} + impl<'a> ProtocolObjectInner<'a> for ReencryptionRequest { fn brand() -> [u8; 4] { *b"ReRq" } fn version() -> (u16, u16) { - (1, 0) + (1, 1) } fn unversioned_to_bytes(&self) -> Box<[u8]> { @@ -71,10 +80,23 @@ impl<'a> ProtocolObjectInner<'a> for ReencryptionRequest { } fn unversioned_from_bytes(minor_version: u16, bytes: &[u8]) -> Option> { - if minor_version == 0 { - Some(messagepack_deserialize(bytes)) - } else { - None + match minor_version { + 0 => { + let req = messagepack_deserialize::(bytes).map(|req| { + ReencryptionRequest { + capsules: req.capsules, + hrac: req.hrac, + encrypted_kfrag: req.encrypted_kfrag, + publisher_verifying_key: req.publisher_verifying_key, + bob_verifying_key: req.bob_verifying_key, + conditions: None, + context: None, + } + }); + Some(req) + } + 1 => Some(messagepack_deserialize(bytes)), + _ => None, } } } diff --git a/nucypher-core/src/retrieval_kit.rs b/nucypher-core/src/retrieval_kit.rs index 5f9ff9ec..c64eae0d 100644 --- a/nucypher-core/src/retrieval_kit.rs +++ b/nucypher-core/src/retrieval_kit.rs @@ -50,13 +50,19 @@ impl RetrievalKit { } } +#[derive(Deserialize)] +struct RetrievalKit0 { + capsule: Capsule, + queried_addresses: BTreeSet
, +} + impl<'a> ProtocolObjectInner<'a> for RetrievalKit { fn brand() -> [u8; 4] { *b"RKit" } fn version() -> (u16, u16) { - (1, 0) + (1, 1) } fn unversioned_to_bytes(&self) -> Box<[u8]> { @@ -64,10 +70,18 @@ impl<'a> ProtocolObjectInner<'a> for RetrievalKit { } fn unversioned_from_bytes(minor_version: u16, bytes: &[u8]) -> Option> { - if minor_version == 0 { - Some(messagepack_deserialize(bytes)) - } else { - None + match minor_version { + 0 => { + let rkit = + messagepack_deserialize::(bytes).map(|rkit| RetrievalKit { + capsule: rkit.capsule, + queried_addresses: rkit.queried_addresses, + conditions: None, + }); + Some(rkit) + } + 1 => Some(messagepack_deserialize(bytes)), + _ => None, } } }