From e4b269e0de27e354caaaea86ec330ef9742c09ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 10 Jan 2025 09:13:13 +0100 Subject: [PATCH] fix: Implement visit_bytes for the Ed25519PublicKey deserialization This fixes the deserialization of the SenderData since it switched to the base64 encoding for serialization of the master key in one of its variants. The issue was introduced in 5ff556f6c3026ab53b21ba0b0a24749ffa715e17. --- .../src/olm/group_sessions/sender_data.rs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/matrix-sdk-crypto/src/olm/group_sessions/sender_data.rs b/crates/matrix-sdk-crypto/src/olm/group_sessions/sender_data.rs index fa79b6b6ab3..697507647f1 100644 --- a/crates/matrix-sdk-crypto/src/olm/group_sessions/sender_data.rs +++ b/crates/matrix-sdk-crypto/src/olm/group_sessions/sender_data.rs @@ -70,13 +70,31 @@ where where A: de::SeqAccess<'de>, { - let mut buf = [0u8; 32]; + let mut buf = [0u8; Ed25519PublicKey::LENGTH]; + for (i, item) in buf.iter_mut().enumerate() { *item = seq.next_element()?.ok_or_else(|| de::Error::invalid_length(i, &self))?; } + let key = Ed25519PublicKey::from_slice(&buf).map_err(|e| de::Error::custom(&e))?; + Ok(Box::new(key)) } + + fn visit_bytes(self, v: &[u8]) -> Result + where + E: de::Error, + { + if v.len() == Ed25519PublicKey::LENGTH { + let mut buf = [0u8; Ed25519PublicKey::LENGTH]; + buf.copy_from_slice(v); + + let key = Ed25519PublicKey::from_slice(&buf).map_err(|e| de::Error::custom(&e))?; + Ok(Box::new(key)) + } else { + Err(de::Error::invalid_length(v.len(), &self)) + } + } } de.deserialize_any(KeyVisitor)