mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-12 18:21:21 -04:00
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 5ff556f6c3.
This commit is contained in:
@@ -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<E>(self, v: &[u8]) -> Result<Self::Value, E>
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user