From b5ae19f0ebd436c4d0b87150b9e807c2e39bf047 Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Fri, 28 Jun 2024 17:51:28 +0000 Subject: [PATCH] serializer: force serialization as array (#546) 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() } }