pub struct KeyMaterial {
pub key: Vec<u8>,
pub nonce: Vec<u8>,
pub salt: Vec<u8>,
pub algorithm: EncryptionAlgorithm,
pub created_at: DateTime<Utc>,
pub expires_at: Option<DateTime<Utc>>,
}Expand description
Key material for encryption/decryption operations with secure memory management
This struct contains all cryptographic material needed for encryption and
decryption operations. It implements secure memory management through the
Zeroize trait to ensure sensitive data is properly cleared from memory
when no longer needed.
§Security Features
- Automatic Zeroization: Keys are securely wiped from memory on drop
- Expiration Support: Keys can have expiration times for security policies
- Algorithm Binding: Keys are bound to specific algorithms
- Timestamp Tracking: Creation time tracking for audit and compliance
§Key Material Components
- Key: The actual encryption/decryption key
- Nonce: Unique number used once per encryption operation
- Salt: Random data used in key derivation
- Algorithm: The encryption algorithm this key is for
- Created At: When the key material was generated
- Expires At: Optional expiration time for key rotation
§Examples
§Memory Security
The key material implements Zeroize to ensure sensitive data is securely
cleared from memory:
§Serialization
Key material can be serialized for storage, but care must be taken to:
- Encrypt serialized key material
- Use secure storage mechanisms
- Implement proper access controls
- Follow key management best practices
Fields§
§key: Vec<u8>The encryption/decryption key (sensitive data)
nonce: Vec<u8>Nonce/initialization vector for encryption operations
salt: Vec<u8>Salt used in key derivation (if applicable)
algorithm: EncryptionAlgorithmThe encryption algorithm this key material is for
created_at: DateTime<Utc>When this key material was created (RFC3339 format)
expires_at: Option<DateTime<Utc>>Optional expiration time for key rotation (RFC3339 format)
Implementations§
Source§impl KeyMaterial
impl KeyMaterial
Source§impl KeyMaterial
impl KeyMaterial
Sourcepub fn with_expiration(self, expires_at: DateTime<Utc>) -> Self
pub fn with_expiration(self, expires_at: DateTime<Utc>) -> Self
Sets expiration time
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Checks if key material is expired
Sourcepub fn nonce_size(&self) -> usize
pub fn nonce_size(&self) -> usize
Gets nonce size in bytes
Trait Implementations§
Source§impl Clone for KeyMaterial
impl Clone for KeyMaterial
Source§fn clone(&self) -> KeyMaterial
fn clone(&self) -> KeyMaterial
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for KeyMaterial
impl Debug for KeyMaterial
Source§impl<'de> Deserialize<'de> for KeyMaterial
impl<'de> Deserialize<'de> for KeyMaterial
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Drop for KeyMaterial
impl Drop for KeyMaterial
Source§impl Serialize for KeyMaterial
impl Serialize for KeyMaterial
Source§impl Zeroize for KeyMaterial
impl Zeroize for KeyMaterial
impl ZeroizeOnDrop for KeyMaterial
Auto Trait Implementations§
impl Freeze for KeyMaterial
impl RefUnwindSafe for KeyMaterial
impl Send for KeyMaterial
impl Sync for KeyMaterial
impl Unpin for KeyMaterial
impl UnwindSafe for KeyMaterial
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
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