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:
Damir Jelić
2025-01-10 09:13:13 +01:00
parent cb72d4375f
commit e4b269e0de

View File

@@ -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)