Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add array support for secrecy #1239

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 19 additions & 0 deletions secrecy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,23 @@ where
}
}

/// A secret array type
///
/// This is a type alias for [`SecretBox<[S; N]>``]
///
/// Notably it has a [`From<[S; N]>`] impl which is the preferred method for construction.
pub type SecretArray<S, const N: usize> = SecretBox<[S; N]>;

impl<S, const N: usize> From<[S; N]> for SecretArray<S, N>
where
S: Zeroize,
[S; N]: Zeroize,
{
fn from(array: [S; N]) -> Self {
Self::from(Box::new(array))
}
}
tzilist marked this conversation as resolved.
Show resolved Hide resolved

/// Secret string type.
///
/// This is a type alias for [`SecretBox<str>`] which supports some helpful trait impls.
Expand Down Expand Up @@ -258,6 +275,8 @@ impl CloneableSecret for u64 {}
impl CloneableSecret for u128 {}
impl CloneableSecret for usize {}

impl<const N: usize, T> CloneableSecret for [T; N] where T: CloneableSecret {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #1245 with just this since it's uncontroversial


/// Expose a reference to an inner secret
pub trait ExposeSecret<S: ?Sized> {
/// Expose secret: this is the only method providing access to a secret.
Expand Down