Skip to content

Commit

Permalink
Merge pull request #6 from Eyob94/chore/add_eq_secretguard
Browse files Browse the repository at this point in the history
chore: equality for secret guards
  • Loading branch information
Eyob94 authored Sep 11, 2024
2 parents ba99bc4 + c373828 commit 4810983
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
cargo-features = ["profile-rustflags"]

[package]
name = "shush-rs"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "A Rust crate designed to manage sensitive data securely by leveraging memory protection mechanisms."
Expand All @@ -29,7 +27,5 @@ windows-sys = { version = "0.59.0", default-features = false, features = [
"Win32_System_Diagnostics_Debug_Extensions",
] }


[profile.release]
panic = "abort"
rustflags = ["-Dwarnings"]
20 changes: 18 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<S: Zeroize> ExposeSecret<S> for SecretBox<S> {
}

/// Secret Guard that holds a reference to the secret.
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct SecretGuard<'a, S>
where
S: Zeroize,
Expand All @@ -224,7 +224,7 @@ where
}

/// Secret Guard that holds a mutable to reference to the secret.
#[derive(Debug)]
#[derive(Debug, Eq, PartialEq)]
pub struct SecretGuardMut<'a, S>
where
S: Zeroize,
Expand Down Expand Up @@ -352,4 +352,20 @@ mod tests {
Err(_) => panic!("Expected Ok variant"),
}
}

#[test]
fn test_secret_guard_equality() {
let secret_guard_a = SecretGuard::new(&5);
let secret_guard_b = SecretGuard::new(&5);

assert!(secret_guard_a == secret_guard_b);

let mut val_a = 7;
let mut val_b = 5;

let secret_guard_mut_a = SecretGuardMut::new(&mut val_a);
let secret_guard_mut_b = SecretGuardMut::new(&mut val_b);

assert!(secret_guard_mut_a != secret_guard_mut_b)
}
}

0 comments on commit 4810983

Please sign in to comment.