Skip to content

Commit

Permalink
serializer: enforce serialization as array
Browse files Browse the repository at this point in the history
The implementation of array deserializer expects the payload to be
serialized as array. Sadly the serializer left the door open for the
underlying serializer to choice either bytes or array, if available.

This would only occur when the objects are used outside yubihsm.rs.

This change was tested on both mockhsm and yubihsm on usb.
  • Loading branch information
baloo committed May 10, 2024
1 parent a3d8cb5 commit 0905d49
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ macro_rules! impl_array_serializers {
($ty:ident, $size:expr) => {
impl ::serde::Serialize for $ty {
fn serialize<S: ::serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.0.serialize(serializer)
use ::serde::ser::SerializeSeq;
let mut seq = serializer.serialize_seq(Some(self.0.len()))?;
for element in self.0.iter() {
seq.serialize_element(element)?;
}
seq.end()
}
}

Expand Down

0 comments on commit 0905d49

Please sign in to comment.