diff --git a/Cargo.lock b/Cargo.lock index 048e355aa..01e4ce2f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3982,6 +3982,7 @@ dependencies = [ "signature 1.6.4", "thiserror", "tor-basic-utils", + "tor-bytes", "tor-llcrypto", "tor-units", ] diff --git a/crates/tor-hscrypto/Cargo.toml b/crates/tor-hscrypto/Cargo.toml index fa12107f9..c65f75128 100644 --- a/crates/tor-hscrypto/Cargo.toml +++ b/crates/tor-hscrypto/Cargo.toml @@ -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", diff --git a/crates/tor-hscrypto/src/macros.rs b/crates/tor-hscrypto/src/macros.rs index dfe84db42..a2d72e66b 100644 --- a/crates/tor-hscrypto/src/macros.rs +++ b/crates/tor-hscrypto/src/macros.rs @@ -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 { + Ok(Self::new(r.extract()?)) + } + } + impl tor_bytes::Writeable for $name { + fn write_onto(&self, w: &mut B) -> tor_bytes::EncodeResult<()> { + w.write_all(&self.0.as_ref()[..]); + Ok(()) + } + } } }