chore(masking): add peek_mut to PeekInterface (#7281)

This commit is contained in:
Kartikeya Hegde
2025-02-22 13:23:51 +05:30
committed by GitHub
parent c14519ebd9
commit 890a265e7b
4 changed files with 15 additions and 0 deletions

View File

@ -6,6 +6,9 @@ use crate::Secret;
pub trait PeekInterface<S> { pub trait PeekInterface<S> {
/// Only method providing access to the secret value. /// Only method providing access to the secret value.
fn peek(&self) -> &S; fn peek(&self) -> &S;
/// Provide a mutable reference to the inner value.
fn peek_mut(&mut self) -> &mut S;
} }
/// Interface that consumes a option secret and returns the value. /// Interface that consumes a option secret and returns the value.

View File

@ -28,6 +28,10 @@ impl PeekInterface<BytesMut> for SecretBytesMut {
fn peek(&self) -> &BytesMut { fn peek(&self) -> &BytesMut {
&self.0 &self.0
} }
fn peek_mut(&mut self) -> &mut BytesMut {
&mut self.0
}
} }
impl fmt::Debug for SecretBytesMut { impl fmt::Debug for SecretBytesMut {

View File

@ -95,6 +95,10 @@ where
fn peek(&self) -> &SecretValue { fn peek(&self) -> &SecretValue {
&self.inner_secret &self.inner_secret
} }
fn peek_mut(&mut self) -> &mut SecretValue {
&mut self.inner_secret
}
} }
impl<SecretValue, MaskingStrategy> From<SecretValue> for Secret<SecretValue, MaskingStrategy> impl<SecretValue, MaskingStrategy> From<SecretValue> for Secret<SecretValue, MaskingStrategy>

View File

@ -32,6 +32,10 @@ impl<Secret: ZeroizableSecret, MaskingStrategy> PeekInterface<Secret>
fn peek(&self) -> &Secret { fn peek(&self) -> &Secret {
&self.inner_secret &self.inner_secret
} }
fn peek_mut(&mut self) -> &mut Secret {
&mut self.inner_secret
}
} }
impl<Secret: ZeroizableSecret, MaskingStrategy> From<Secret> impl<Secret: ZeroizableSecret, MaskingStrategy> From<Secret>