pub struct CryptoSensitive<const N: usize> { /* private fields */ }Expand description
A cryptographic material represented in a cross-platform way, as a fixed-length array in a well-defined format.
Thus, it can be imported into any Crypto provider and exported from it without
worrying about endianness or other platform-specific representation issues.
The reason for wrapping the array with a newtype is so that the following protection measures are taken:
- The material is not accidentally printed in logs or debug output.
- The material has a single
access/access_mutmethod and deliberately does not implementDereforAsReftraits to avoid accidental leakage. - The material is zeroed out when dropped; note however that this has a limited use case, in Rust, because of the Rust move semantics.
Regarding sensitivity, rs-matter takes a radical approach and assumes that
all cryptographic material is sensitive. Including, but not limited to:
- Secret keys (obviously)
- Signatures (because they can leak information about the secret key)
- Hashes (because they can be pre-images of sensitive data)
- Public keys (just in case)
Implementations§
Source§impl<const N: usize> CryptoSensitive<N>
impl<const N: usize> CryptoSensitive<N>
Sourcepub const fn new() -> CryptoSensitive<N>
pub const fn new() -> CryptoSensitive<N>
Create a new zeroed CryptoSensitive instance.
Sourcepub const fn new_from_ref(
other: CryptoSensitiveRef<'_, N>,
) -> CryptoSensitive<N>
pub const fn new_from_ref( other: CryptoSensitiveRef<'_, N>, ) -> CryptoSensitive<N>
Create a new CryptoSensitive instance by loading data from the provided reference.
Sourcepub fn init() -> impl Init<CryptoSensitive<N>>
pub fn init() -> impl Init<CryptoSensitive<N>>
Return an in-place initializer for a zeroed CryptoSensitive instance.
Sourcepub const fn reference(&self) -> CryptoSensitiveRef<'_, N>
pub const fn reference(&self) -> CryptoSensitiveRef<'_, N>
Get a reference to this cryptographic material.
Sourcepub const fn load(&mut self, other: CryptoSensitiveRef<'_, N>)
pub const fn load(&mut self, other: CryptoSensitiveRef<'_, N>)
Load data from another cryptographic material reference.
Sourcepub const fn load_from_array(&mut self, data: &[u8; N])
pub const fn load_from_array(&mut self, data: &[u8; N])
Load data from a byte array.
Sourcepub fn try_load_from_slice(&mut self, data: &[u8]) -> Result<(), Error>
pub fn try_load_from_slice(&mut self, data: &[u8]) -> Result<(), Error>
Try to load data from a byte slice.
Returns an error if the slice length does not match the expected length.
Sourcepub const fn access(&self) -> &[u8; N]
pub const fn access(&self) -> &[u8; N]
Access the underlying data as a byte array reference.
NOTE: care should be taken when using this method, as it exposes the sensitive data.
Sourcepub const fn access_mut(&mut self) -> &mut [u8; N]
pub const fn access_mut(&mut self) -> &mut [u8; N]
Access the underlying data as a mutable byte array reference.
NOTE: care should be taken when using this method, as it exposes the sensitive data.
Trait Implementations§
Source§impl<const N: usize> Clone for CryptoSensitive<N>
impl<const N: usize> Clone for CryptoSensitive<N>
Source§fn clone(&self) -> CryptoSensitive<N>
fn clone(&self) -> CryptoSensitive<N>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const N: usize> Debug for CryptoSensitive<N>
impl<const N: usize> Debug for CryptoSensitive<N>
Source§impl<const N: usize> Default for CryptoSensitive<N>
impl<const N: usize> Default for CryptoSensitive<N>
Source§fn default() -> CryptoSensitive<N>
fn default() -> CryptoSensitive<N>
Source§impl<const N: usize> Drop for CryptoSensitive<N>
impl<const N: usize> Drop for CryptoSensitive<N>
Source§impl<'a, const N: usize> From<&'a CryptoSensitive<N>> for CryptoSensitiveRef<'a, N>
impl<'a, const N: usize> From<&'a CryptoSensitive<N>> for CryptoSensitiveRef<'a, N>
Source§fn from(cs: &'a CryptoSensitive<N>) -> CryptoSensitiveRef<'a, N>
fn from(cs: &'a CryptoSensitive<N>) -> CryptoSensitiveRef<'a, N>
Source§impl<const N: usize> From<CryptoSensitiveRef<'_, N>> for CryptoSensitive<N>
impl<const N: usize> From<CryptoSensitiveRef<'_, N>> for CryptoSensitive<N>
Source§fn from(other: CryptoSensitiveRef<'_, N>) -> CryptoSensitive<N>
fn from(other: CryptoSensitiveRef<'_, N>) -> CryptoSensitive<N>
Source§impl<'a, const N: usize> FromTLV<'a> for CryptoSensitive<N>
impl<'a, const N: usize> FromTLV<'a> for CryptoSensitive<N>
Source§fn from_tlv(element: &TLVElement<'a>) -> Result<CryptoSensitive<N>, Error>
fn from_tlv(element: &TLVElement<'a>) -> Result<CryptoSensitive<N>, Error>
Source§fn init_from_tlv(
element: TLVElement<'a>,
) -> impl Init<CryptoSensitive<N>, Error>
fn init_from_tlv( element: TLVElement<'a>, ) -> impl Init<CryptoSensitive<N>, Error>
Source§fn nullable_from_tlv(element: &TLVElement<'a>) -> Result<Self, Error>
fn nullable_from_tlv(element: &TLVElement<'a>) -> Result<Self, Error>
Source§fn init_nullable_from_tlv(element: TLVElement<'a>) -> impl Init<Self, Error>
fn init_nullable_from_tlv(element: TLVElement<'a>) -> impl Init<Self, Error>
Source§impl<const N: usize> ToTLV for CryptoSensitive<N>
impl<const N: usize> ToTLV for CryptoSensitive<N>
Source§fn to_tlv<W>(&self, tag: &TLVTag, tw: W) -> Result<(), Error>where
W: TLVWrite,
fn to_tlv<W>(&self, tag: &TLVTag, tw: W) -> Result<(), Error>where
W: TLVWrite,
Source§fn tlv_iter(&self, tag: TLVTag) -> impl Iterator<Item = Result<TLV<'_>, Error>>
fn tlv_iter(&self, tag: TLVTag) -> impl Iterator<Item = Result<TLV<'_>, Error>>
TLV instances by potentially borrowing
data from the type.Auto Trait Implementations§
impl<const N: usize> Freeze for CryptoSensitive<N>
impl<const N: usize> RefUnwindSafe for CryptoSensitive<N>
impl<const N: usize> Send for CryptoSensitive<N>
impl<const N: usize> Sync for CryptoSensitive<N>
impl<const N: usize> Unpin for CryptoSensitive<N>
impl<const N: usize> UnsafeUnpin for CryptoSensitive<N>
impl<const N: usize> UnwindSafe for CryptoSensitive<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more