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 @@ -15,10 +15,10 @@
use crate::constants::SECURITY_PARAMETER;
use crate::header::keys::PayloadKey;
use crate::{Error, ErrorKind, Result};
use arrayref::array_ref;

Check warning on line 18 in src/payload/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `arrayref::array_ref`

warning: unused import: `arrayref::array_ref` --> src/payload/mod.rs:18:5 | 18 | use arrayref::array_ref; | ^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
use blake2::VarBlake2b;

Check warning on line 19 in src/payload/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `blake2::VarBlake2b`

warning: unused import: `blake2::VarBlake2b` --> src/payload/mod.rs:19:5 | 19 | use blake2::VarBlake2b; | ^^^^^^^^^^^^^^^^^^
use chacha::ChaCha; // we might want to swap this one with a different implementation

Check warning on line 20 in src/payload/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `chacha::ChaCha`

warning: unused import: `chacha::ChaCha` --> src/payload/mod.rs:20:5 | 20 | use chacha::ChaCha; // we might want to swap this one with a different implementation | ^^^^^^^^^^^^^^
use lioness::Lioness;

Check warning on line 21 in src/payload/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `lioness::Lioness`

warning: unused import: `lioness::Lioness` --> src/payload/mod.rs:21:5 | 21 | use lioness::Lioness; | ^^^^^^^^^^^^^^^^

// payload consists of security parameter long zero-padding, plaintext and '1' byte to indicate start of padding
// (it can optionally be followed by zero-padding
Expand Down Expand Up @@ -89,10 +89,10 @@
/// Note: this function should only ever be called in [`encapsulate_message`] after
/// [`validate_parameters`] was performed.
fn set_final_payload(plaintext_message: &[u8], payload_size: usize) -> Self {
let final_payload: Vec<u8> = std::iter::repeat(0u8)

Check failure on line 92 in src/payload/mod.rs

View workflow job for this annotation

GitHub Actions / ci (nightly)

this `repeat().take()` can be written more concisely

Check failure on line 92 in src/payload/mod.rs

View workflow job for this annotation

GitHub Actions / ci (nightly)

this `repeat().take()` can be written more concisely
.take(SECURITY_PARAMETER) // start with zero-padding
.chain(plaintext_message.iter().cloned()) // put the plaintext
.chain(std::iter::repeat(1u8).take(1)) // add single 1 byte to indicate start of padding

Check failure on line 95 in src/payload/mod.rs

View workflow job for this annotation

GitHub Actions / ci (nightly)

this `repeat().take()` can be written more concisely

Check failure on line 95 in src/payload/mod.rs

View workflow job for this annotation

GitHub Actions / ci (nightly)

this `repeat().take()` can be written more concisely
.chain(std::iter::repeat(0u8)) // and fill everything else with zeroes
.take(payload_size) // take however much we need (remember, iterators are lazy)
.collect();
Expand All @@ -101,6 +101,7 @@
}

/// 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 @@
Ok(self)
}

#[cfg(feature = "mock")]
fn add_encryption_layer(mut self, payload_enc_key: &PayloadKey) -> Result<Self> {

Check warning on line 122 in src/payload/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

variable does not need to be mutable

warning: variable does not need to be mutable --> src/payload/mod.rs:122:29 | 122 | fn add_encryption_layer(mut self, payload_enc_key: &PayloadKey) -> Result<Self> { | ----^^^^ | | | help: remove this `mut` | = note: `#[warn(unused_mut)]` on by default

Check warning on line 122 in src/payload/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `payload_enc_key`

warning: unused variable: `payload_enc_key` --> src/payload/mod.rs:122:39 | 122 | fn add_encryption_layer(mut self, payload_enc_key: &PayloadKey) -> Result<Self> { | ^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_payload_enc_key` | = note: `#[warn(unused_variables)]` on by default
// 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 @@
Ok(self)
}

#[cfg(feature = "mock")]
pub fn unwrap(mut self, payload_key: &PayloadKey) -> Result<Self> {

Check warning on line 146 in src/payload/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

variable does not need to be mutable

warning: variable does not need to be mutable --> src/payload/mod.rs:146:19 | 146 | pub fn unwrap(mut self, payload_key: &PayloadKey) -> Result<Self> { | ----^^^^ | | | help: remove this `mut`

Check warning on line 146 in src/payload/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `payload_key`

warning: unused variable: `payload_key` --> src/payload/mod.rs:146:29 | 146 | pub fn unwrap(mut self, payload_key: &PayloadKey) -> Result<Self> { | ^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_payload_key`
// 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 @@
}

#[test]
#[cfg(not(feature = "mock"))]
fn it_fails_to_recover_plaintext_from_invalid_payload() {
let message = vec![42u8; 160];

Expand Down
Loading