diff --git a/crates/tor-bytes/semver.md b/crates/tor-bytes/semver.md index 055c64ad2..4fbc4a0ff 100644 --- a/crates/tor-bytes/semver.md +++ b/crates/tor-bytes/semver.md @@ -1 +1,2 @@ ADDED: Cursor functionality in Reader. +ADDED: Readable+Writeable for CtByteArray. diff --git a/crates/tor-bytes/src/impls.rs b/crates/tor-bytes/src/impls.rs index ee9c8a413..0f36948f7 100644 --- a/crates/tor-bytes/src/impls.rs +++ b/crates/tor-bytes/src/impls.rs @@ -298,6 +298,24 @@ mod u8_array_impls { } } +/// Implement Readable and Writeable for `CtByteArray` +mod ctbytearray_impls { + use super::*; + use tor_llcrypto::util::ct::CtByteArray; + impl Writeable for CtByteArray { + fn write_onto(&self, b: &mut B) -> EncodeResult<()> { + b.write_all(&self.as_ref()[..]); + Ok(()) + } + } + + impl Readable for CtByteArray { + fn take_from(r: &mut Reader<'_>) -> Result { + Ok(CtByteArray::from(r.extract::<[u8; N]>()?)) + } + } +} + #[cfg(test)] mod tests { #![allow(clippy::unwrap_used)]