pub struct SecretKey { /* private fields */ }
Expand description
A type to represent a secret key.
As default it will randomly generate a SecretKey
of 32 bytes.
Note:
Due to the return type of the Default trait, the default()
method cannot let the caller
handle a failing CSPRNG. If the CSPRNG fails, that function panics. If handling a failing CSPRNG’s
error is needed, use instead generate()
.
Exceptions:
An exception will be thrown if:
slice
is empty.- The
OsRng
fails to initialize or read from its source. length
is 0.
Security:
- Avoid using
unprotected_as_bytes()
whenever possible, as it breaks all protections that the type implements.
Implementations§
source§impl SecretKey
impl SecretKey
sourcepub fn from_slice(slice: &[u8]) -> Result<SecretKey, UnknownCryptoError>
pub fn from_slice(slice: &[u8]) -> Result<SecretKey, UnknownCryptoError>
Make an object from a given byte slice.
sourcepub fn unprotected_as_bytes(&self) -> &[u8] ⓘ
pub fn unprotected_as_bytes(&self) -> &[u8] ⓘ
Return the object as byte slice. Warning: Should not be used unless strictly needed. This breaks protections that the type implements.
sourcepub fn get_length(&self) -> usize
pub fn get_length(&self) -> usize
Return the length of the object.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for SecretKey
impl Send for SecretKey
impl Sync for SecretKey
impl Unpin for SecretKey
impl UnwindSafe for SecretKey
Blanket Implementations§
source§impl<T> Clear for Twhere
T: InitializableFromZeroed + ?Sized,
impl<T> Clear for Twhere
T: InitializableFromZeroed + ?Sized,
source§impl<T> InitializableFromZeroed for Twhere
T: Default,
impl<T> InitializableFromZeroed for Twhere
T: Default,
source§unsafe fn initialize(place: *mut T)
unsafe fn initialize(place: *mut T)
Called to initialize a place to a valid value, after it is set
to all-bits-zero. Read more