Skip to content

Commit e4fbb5e

Browse files
committed
fix Serializable implementation for Vec<u8>
1 parent bc0c45a commit e4fbb5e

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

crates/core/src/bytes_ser_de.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ impl Serializer {
189189
///
190190
/// - `array` : array of bytes to write
191191
pub fn write_array(&mut self, array: &[u8]) -> Result<usize, CryptoCoreError> {
192-
self.0
193-
.write(array)
194-
.map_err(|error| CryptoCoreError::SerializationIoError {
192+
<Vec<u8> as Write>::write(&mut self.0, array).map_err(|error| {
193+
CryptoCoreError::SerializationIoError {
195194
bytes_len: array.len(),
196195
error,
197-
})
196+
}
197+
})
198198
}
199199

200200
/// Writes a vector of Boolean values in a packed manner.
@@ -509,6 +509,22 @@ where
509509
}
510510
}
511511

512+
impl Serializable for Vec<u8> {
513+
type Error = CryptoCoreError;
514+
515+
fn length(&self) -> usize {
516+
self.len().length() + self.len()
517+
}
518+
519+
fn write(&self, ser: &mut Serializer) -> Result<usize, Self::Error> {
520+
ser.write_vec(self)
521+
}
522+
523+
fn read(de: &mut Deserializer) -> Result<Self, Self::Error> {
524+
de.read_vec()
525+
}
526+
}
527+
512528
impl<T: Serializable> Serializable for Vec<T>
513529
where
514530
T::Error: From<CryptoCoreError>,

0 commit comments

Comments
 (0)