Skip to content

Commit

Permalink
fix: Implement visit_bytes for the Ed25519PublicKey deserialization
Browse files Browse the repository at this point in the history
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 5ff556f.
  • Loading branch information
poljar committed Jan 10, 2025
1 parent cb72d43 commit e4b269e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion crates/matrix-sdk-crypto/src/olm/group_sessions/sender_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e4b269e

Please sign in to comment.