From c3738289c1ea4fdc6680448a796a39178c810504 Mon Sep 17 00:00:00 2001 From: Eyob Date: Wed, 11 Sep 2024 16:49:43 +0300 Subject: [PATCH] chore: equality for secret guards --- Cargo.lock | 4 ++-- Cargo.toml | 6 +----- src/lib.rs | 20 ++++++++++++++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d9712ed..10f0ee3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,8 +19,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] -name = "shush" -version = "0.1.0" +name = "shush-rs" +version = "0.1.1" dependencies = [ "errno", "libc", diff --git a/Cargo.toml b/Cargo.toml index 61f6f67..cdaf952 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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." @@ -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"] diff --git a/src/lib.rs b/src/lib.rs index 01d6c89..a826e55 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -204,7 +204,7 @@ impl ExposeSecret for SecretBox { } /// Secret Guard that holds a reference to the secret. -#[derive(Debug)] +#[derive(Debug, Eq, PartialEq)] pub struct SecretGuard<'a, S> where S: Zeroize, @@ -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, @@ -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) + } }