pub struct Key(/* private fields */);Expand description
A 32-byte XChaCha20-Poly1305 key. Zeroized on drop and never printed.
The bytes live on the heap, so moving a key, or growing a list of keys, moves a pointer and leaves no copy of the bytes behind. Keys compare in constant time.
Implementations§
Source§impl Key
impl Key
pub const LEN: usize = 32
Sourcepub fn from_bytes(bytes: [u8; 32]) -> Key
pub fn from_bytes(bytes: [u8; 32]) -> Key
A key holding bytes. Copies the caller still holds are the caller’s to zeroize.
Sourcepub fn from_slice(bytes: &[u8]) -> Option<Key>
pub fn from_slice(bytes: &[u8]) -> Option<Key>
Returns None unless bytes is exactly 32 bytes long.
Sourcepub fn from_base64(text: &str) -> Result<Key, KeyError>
pub fn from_base64(text: &str) -> Result<Key, KeyError>
A key written as standard base64, with or without = padding, as kinship keygen
prints it. Surrounding whitespace is ignored.
Sourcepub fn to_base64(&self) -> Zeroizing<String>
pub fn to_base64(&self) -> Zeroizing<String>
The key as padded standard base64, the form from_base64 reads and
kinship keygen prints. The text is the secret itself: never log it. It is zeroized when
dropped, and written into its final allocation, so no copy is left behind.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Key
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnsafeUnpin for Key
impl UnwindSafe for Key
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
Mutably borrows from an owned value. Read more