diff --git a/Cargo.toml b/Cargo.toml index 47fcfc6..8ff60c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,3 +38,5 @@ criterion = "0.5.1" name = "benchmarks" harness = false +[features] +mock = [] diff --git a/src/packet/builder.rs b/src/packet/builder.rs index 3b45546..425921d 100644 --- a/src/packet/builder.rs +++ b/src/packet/builder.rs @@ -47,7 +47,7 @@ impl<'a> SphinxPacketBuilder<'a> { } } -impl<'a> Default for SphinxPacketBuilder<'a> { +impl Default for SphinxPacketBuilder<'_> { fn default() -> Self { SphinxPacketBuilder { payload_size: DEFAULT_PAYLOAD_SIZE, diff --git a/src/payload/mod.rs b/src/payload/mod.rs index e9e6153..9de5cf9 100644 --- a/src/payload/mod.rs +++ b/src/payload/mod.rs @@ -101,6 +101,7 @@ impl Payload { } /// Tries to add an additional layer of encryption onto self. + #[cfg(not(feature = "mock"))] fn add_encryption_layer(mut self, payload_enc_key: &PayloadKey) -> Result { let lioness_cipher = Lioness::::new_raw(array_ref!( payload_enc_key, @@ -117,7 +118,15 @@ impl Payload { Ok(self) } + #[cfg(feature = "mock")] + fn add_encryption_layer(mut self, payload_enc_key: &PayloadKey) -> Result { + // Mock implementation for testing purposes + // noop + Ok(self) + } + /// Tries to remove single layer of encryption from self. + #[cfg(not(feature = "mock"))] pub fn unwrap(mut self, payload_key: &PayloadKey) -> Result { let lioness_cipher = Lioness::::new_raw(array_ref!( payload_key, @@ -133,6 +142,13 @@ impl Payload { Ok(self) } + #[cfg(feature = "mock")] + pub fn unwrap(mut self, payload_key: &PayloadKey) -> Result { + // Mock implementation for testing purposes + // noop + Ok(self) + } + /// After calling [`unwrap`] required number of times with correct `payload_keys`, tries to parse /// the resultant payload content into original encapsulated plaintext message. pub fn recover_plaintext(self) -> Result> { @@ -451,6 +467,7 @@ mod plaintext_recovery { } #[test] + #[cfg(not(feature = "mock"))] fn it_fails_to_recover_plaintext_from_invalid_payload() { let message = vec![42u8; 160];