Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ criterion = "0.5.1"
name = "benchmarks"
harness = false

[features]
mock = []
2 changes: 1 addition & 1 deletion src/packet/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions src/payload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
let lioness_cipher = Lioness::<VarBlake2b, ChaCha>::new_raw(array_ref!(
payload_enc_key,
Expand All @@ -117,7 +118,15 @@ impl Payload {
Ok(self)
}

#[cfg(feature = "mock")]
fn add_encryption_layer(mut self, payload_enc_key: &PayloadKey) -> Result<Self> {
// 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<Self> {
let lioness_cipher = Lioness::<VarBlake2b, ChaCha>::new_raw(array_ref!(
payload_key,
Expand All @@ -133,6 +142,13 @@ impl Payload {
Ok(self)
}

#[cfg(feature = "mock")]
pub fn unwrap(mut self, payload_key: &PayloadKey) -> Result<Self> {
// 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<Vec<u8>> {
Expand Down Expand Up @@ -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];

Expand Down