pub struct EncryptionKeyId(/* private fields */);Expand description
Encryption key identifier value object for secure key management
This value object provides type-safe encryption key references with comprehensive validation, key rotation support, and environment-aware key management capabilities. It implements Domain-Driven Design (DDD) value object patterns with immutable semantics and business rule enforcement.
§Key Features
- Type Safety: Strongly-typed key identifiers that cannot be confused with strings
- Format Validation: Comprehensive validation of key ID format and constraints
- Key Rotation: Built-in support for key versioning and rotation
- Environment Awareness: Automatic detection of production/development environments
- Algorithm Support: Multi-algorithm key identification and validation
- Immutable Semantics: Value objects that cannot be modified after creation
§Key ID Format
The key ID follows a structured format: {algorithm}-{version}-{identifier}
§Examples
aes256-v1-prod-2024- AES-256 production key, version 1chacha20-v2-dev-abc123- ChaCha20 development key, version 2rsa2048-v3-staging-key001- RSA-2048 staging key, version 3
§Constraints
- Length: 8-64 characters total
- Characters: Alphanumeric, hyphens (-), underscores (_)
- Structure: Must contain at least 2 separators
- Validation: Cannot start or end with separators
§Security Considerations
- Environment Separation: Clear separation between production and development keys
- Access Control: Environment-based access control patterns
- Audit Trail: Complete key usage and lifecycle tracking
- Key Rotation: Regular key rotation with version management
§Usage Examples
§Cross-Platform Compatibility
- Rust:
EncryptionKeyIdnewtype wrapper - Go:
EncryptionKeyIDstruct with equivalent interface - JSON: String representation for API compatibility
- Database: TEXT column with validation constraints
Implementations§
Source§impl EncryptionKeyId
impl EncryptionKeyId
Sourcepub fn new(key_id: String) -> Result<Self, PipelineError>
pub fn new(key_id: String) -> Result<Self, PipelineError>
Creates a new encryption key ID with format validation
§Purpose
Creates a type-safe encryption key identifier with comprehensive format validation. Supports structured key IDs with algorithm, version, and identifier components.
§Why
Type-safe key IDs provide:
- Prevention of key management errors
- Structured key versioning and rotation
- Environment separation (production/development)
- Audit trail support
§Arguments
key_id- Key identifier string (format:algorithm-version-identifier)
§Returns
Ok(EncryptionKeyId)- Valid key IDErr(PipelineError::InvalidConfiguration)- Invalid format
§Errors
- Key ID is empty or < 8 characters
- Key ID exceeds 64 characters
- Contains invalid characters
- Starts/ends with separator
- Missing required components
§Examples
Sourcepub fn parse(key_id: &str) -> Result<Self, PipelineError>
pub fn parse(key_id: &str) -> Result<Self, PipelineError>
Creates an encryption key ID from a string slice
Sourcepub fn identifier(&self) -> Option<&str>
pub fn identifier(&self) -> Option<&str>
Extracts the identifier portion from the key ID
Sourcepub fn is_production(&self) -> bool
pub fn is_production(&self) -> bool
Checks if this is a production key
Sourcepub fn is_development(&self) -> bool
pub fn is_development(&self) -> bool
Checks if this is a development key
Sourcepub fn supports_algorithm(&self, algorithm: &str) -> bool
pub fn supports_algorithm(&self, algorithm: &str) -> bool
Checks if this key supports the given algorithm
Sourcepub fn version_number(&self) -> Option<u32>
pub fn version_number(&self) -> Option<u32>
Gets the key version number if available
Sourcepub fn next_version(&self) -> Result<Self, PipelineError>
pub fn next_version(&self) -> Result<Self, PipelineError>
Creates a new version of this key for key rotation
§Purpose
Generates the next version of the encryption key for key rotation. Automatically increments version number while preserving algorithm and identifier.
§Why
Key rotation provides:
- Enhanced security through regular key updates
- Backward compatibility with version tracking
- Automated versioning without manual configuration
- Audit trail of key lifecycle
§Returns
Ok(EncryptionKeyId)- Next version of the keyErr(PipelineError)- Invalid format or rotation failed
§Errors
Returns error if key ID format doesn’t support versioning.
§Examples
Sourcepub fn validate(&self) -> Result<(), PipelineError>
pub fn validate(&self) -> Result<(), PipelineError>
Validates the encryption key ID
Source§impl EncryptionKeyId
Predefined encryption key ID builders
impl EncryptionKeyId
Predefined encryption key ID builders
Sourcepub fn aes256(version: u32, identifier: &str) -> Result<Self, PipelineError>
pub fn aes256(version: u32, identifier: &str) -> Result<Self, PipelineError>
Creates an AES-256 key ID
Sourcepub fn chacha20(version: u32, identifier: &str) -> Result<Self, PipelineError>
pub fn chacha20(version: u32, identifier: &str) -> Result<Self, PipelineError>
Creates a ChaCha20 key ID
Sourcepub fn production(
algorithm: &str,
version: u32,
identifier: &str,
) -> Result<Self, PipelineError>
pub fn production( algorithm: &str, version: u32, identifier: &str, ) -> Result<Self, PipelineError>
Creates a production key ID
Sourcepub fn development(
algorithm: &str,
version: u32,
identifier: &str,
) -> Result<Self, PipelineError>
pub fn development( algorithm: &str, version: u32, identifier: &str, ) -> Result<Self, PipelineError>
Creates a development key ID
Trait Implementations§
Source§impl AsRef<str> for EncryptionKeyId
impl AsRef<str> for EncryptionKeyId
Source§impl Clone for EncryptionKeyId
impl Clone for EncryptionKeyId
Source§fn clone(&self) -> EncryptionKeyId
fn clone(&self) -> EncryptionKeyId
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EncryptionKeyId
impl Debug for EncryptionKeyId
Source§impl Display for EncryptionKeyId
impl Display for EncryptionKeyId
Source§impl From<EncryptionKeyId> for String
impl From<EncryptionKeyId> for String
Source§fn from(key_id: EncryptionKeyId) -> Self
fn from(key_id: EncryptionKeyId) -> Self
Source§impl FromStr for EncryptionKeyId
impl FromStr for EncryptionKeyId
Source§impl Hash for EncryptionKeyId
impl Hash for EncryptionKeyId
Source§impl Ord for EncryptionKeyId
impl Ord for EncryptionKeyId
Source§fn cmp(&self, other: &EncryptionKeyId) -> Ordering
fn cmp(&self, other: &EncryptionKeyId) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for EncryptionKeyId
impl PartialEq for EncryptionKeyId
Source§impl PartialOrd for EncryptionKeyId
impl PartialOrd for EncryptionKeyId
impl Eq for EncryptionKeyId
impl StructuralPartialEq for EncryptionKeyId
Auto Trait Implementations§
impl Freeze for EncryptionKeyId
impl RefUnwindSafe for EncryptionKeyId
impl Send for EncryptionKeyId
impl Sync for EncryptionKeyId
impl Unpin for EncryptionKeyId
impl UnwindSafe for EncryptionKeyId
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