hscrypto: Make several types Readable+Writeable

Specifically, RendCookie, Subcredential, HsId, and HsBlindId.
This commit is contained in:
Nick Mathewson 2023-02-27 12:31:31 -05:00
parent 886faa96b3
commit d69ed3bc62
3 changed files with 13 additions and 0 deletions

1
Cargo.lock generated
View File

@ -3982,6 +3982,7 @@ dependencies = [
"signature 1.6.4",
"thiserror",
"tor-basic-utils",
"tor-bytes",
"tor-llcrypto",
"tor-units",
]

View File

@ -22,6 +22,7 @@ rand_core = "0.6.2"
serde = { version = "1.0.103", features = ["derive"] }
signature = "1"
thiserror = "1"
tor-bytes = { version = "0.6.1", path = "../tor-bytes" }
tor-llcrypto = { version = "0.4.2", path = "../tor-llcrypto", features = [
"hsv3-client",
"hsv3-service",

View File

@ -59,6 +59,17 @@ macro_rules! define_bytes {
inp.0.into()
}
}
impl tor_bytes::Readable for $name {
fn take_from(r: &mut tor_bytes::Reader<'_>) -> tor_bytes::Result<Self> {
Ok(Self::new(r.extract()?))
}
}
impl tor_bytes::Writeable for $name {
fn write_onto<B:tor_bytes::Writer+?Sized>(&self, w: &mut B) -> tor_bytes::EncodeResult<()> {
w.write_all(&self.0.as_ref()[..]);
Ok(())
}
}
}
}