diff --git a/secrecy/src/lib.rs b/secrecy/src/lib.rs index fef8f404..48570aeb 100644 --- a/secrecy/src/lib.rs +++ b/secrecy/src/lib.rs @@ -36,7 +36,7 @@ extern crate alloc; -use alloc::{boxed::Box, string::String}; +use alloc::{boxed::Box, string::String, vec::Vec}; use core::{ any, fmt::{self, Debug}, @@ -167,6 +167,23 @@ impl ExposeSecretMut for SecretBox { } } +/// Secret slice type. +/// +/// This is a type alias for [`SecretBox<[S]>`] which supports some helpful trait impls. +/// +/// Notably it has a [`From>`] impl which is the preferred method for construction. +pub type SecretSlice = SecretBox<[S]>; + +impl From> for SecretSlice +where + S: Zeroize, + [S]: Zeroize, +{ + fn from(vec: Vec) -> Self { + Self::from(vec.into_boxed_slice()) + } +} + /// Secret string type. /// /// This is a type alias for [`SecretBox`] which supports some helpful trait impls.