tor-bytes: impl Readable and Writeable for CtByteArray.

This commit is contained in:
Nick Mathewson 2023-02-28 09:43:17 -05:00
parent d658fcfc52
commit 0f88c5131f
2 changed files with 19 additions and 0 deletions

View File

@ -1 +1,2 @@
ADDED: Cursor functionality in Reader.
ADDED: Readable+Writeable for CtByteArray.

View File

@ -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<const N: usize> Writeable for CtByteArray<N> {
fn write_onto<B: Writer + ?Sized>(&self, b: &mut B) -> EncodeResult<()> {
b.write_all(&self.as_ref()[..]);
Ok(())
}
}
impl<const N: usize> Readable for CtByteArray<N> {
fn take_from(r: &mut Reader<'_>) -> Result<Self> {
Ok(CtByteArray::from(r.extract::<[u8; N]>()?))
}
}
}
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]