From cf22b9e083c32ddaeb11041eea0b7aa17aca3535 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Fri, 10 May 2024 10:36:12 -0700 Subject: [PATCH] serializer: enforce serialization as array 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. --- src/serialization.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/serialization.rs b/src/serialization.rs index 6b552fd4..005eed48 100644 --- a/src/serialization.rs +++ b/src/serialization.rs @@ -25,7 +25,12 @@ macro_rules! impl_array_serializers { ($ty:ident, $size:expr) => { impl ::serde::Serialize for $ty { fn serialize(&self, serializer: S) -> Result { - 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() } }