pub struct SymmetricKey { /* private fields */ }Expand description
A 256-bit symmetric encryption key for ChaCha20-Poly1305
Implementations§
Source§impl SymmetricKey
impl SymmetricKey
Sourcepub fn generate() -> SymmetricKey
pub fn generate() -> SymmetricKey
Generate a new random 256-bit symmetric key
Uses the OS random number generator to create a cryptographically secure key.
§Example
use saorsa_pqc::symmetric::SymmetricKey;
let key = SymmetricKey::generate();Sourcepub const fn from_bytes(key_bytes: [u8; 32]) -> SymmetricKey
pub const fn from_bytes(key_bytes: [u8; 32]) -> SymmetricKey
Sourcepub fn from_slice(key_bytes: &[u8]) -> Result<SymmetricKey, SymmetricError>
pub fn from_slice(key_bytes: &[u8]) -> Result<SymmetricKey, SymmetricError>
Create a symmetric key from a byte slice
§Arguments
key_bytes- A byte slice containing exactly 32 bytes
§Errors
Returns SymmetricError::InvalidKeyLength if the slice is not exactly 32 bytes.
§Example
use saorsa_pqc::symmetric::SymmetricKey;
let key_vec = vec![0u8; 32];
let key = SymmetricKey::from_slice(&key_vec)?;Trait Implementations§
Source§impl Clone for SymmetricKey
impl Clone for SymmetricKey
Source§fn clone(&self) -> SymmetricKey
fn clone(&self) -> SymmetricKey
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SymmetricKey
impl Debug for SymmetricKey
Source§impl<'de> Deserialize<'de> for SymmetricKey
impl<'de> Deserialize<'de> for SymmetricKey
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<SymmetricKey, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<SymmetricKey, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Drop for SymmetricKey
impl Drop for SymmetricKey
Source§impl Serialize for SymmetricKey
impl Serialize for SymmetricKey
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for SymmetricKey
impl RefUnwindSafe for SymmetricKey
impl Send for SymmetricKey
impl Sync for SymmetricKey
impl Unpin for SymmetricKey
impl UnwindSafe for SymmetricKey
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