pub struct Algorithm(/* private fields */);Expand description
Algorithm value object for pipeline stage processing
§Purpose
Type-safe algorithm specification that provides:
- Validation of algorithm names and formats
- Algorithm-specific behavior and constraints
- Immutable value semantics (DDD value object)
- Cross-language compatibility
§Supported Algorithms
- Compression: brotli, gzip, zstd, lz4
- Encryption: aes-256-gcm, chacha20-poly1305, aes-128-gcm
- Hashing: sha256, sha512, blake3
- Custom: User-defined algorithms
§Cross-Language Mapping
- Rust:
Algorithm(newtype wrapper) - Go:
Algorithmstruct with same interface - JSON: String representation
- SQLite: TEXT column with validation
§Examples
Implementations§
Source§impl Algorithm
impl Algorithm
Sourcepub fn new(name: String) -> Result<Self, PipelineError>
pub fn new(name: String) -> Result<Self, PipelineError>
Creates a new algorithm with validated name
§Purpose
Creates an Algorithm value object after validating the algorithm name
against strict format rules. This ensures all algorithm instances
are valid and type-safe. # Why
Algorithm names must follow a consistent format for:
- Cross-language compatibility (Rust, Go, JSON)
- Database storage validation
- Configuration file parsing
- Prevention of injection attacks
§Arguments
name- The algorithm name string. Must:- Not be empty
- Be 1-64 characters long
- Contain only lowercase letters, hyphens, and digits
- Not start with a hyphen or digit
- Not end with a hyphen
- Not contain consecutive hyphens
§Returns
Ok(Algorithm)- Successfully validated algorithmErr(PipelineError::InvalidConfiguration)- Name validation failed
§Errors
Returns PipelineError::InvalidConfiguration when:
- Name is empty
- Name exceeds 64 characters
- Name contains invalid characters (uppercase, special chars)
- Name starts/ends with hyphen
- Name starts with digit
- Name contains consecutive hyphens (“–”)
§Examples
Sourcepub fn parse(name: &str) -> Result<Self, PipelineError>
pub fn parse(name: &str) -> Result<Self, PipelineError>
Creates an algorithm from a string slice
§Purpose
Convenience constructor that accepts a string slice instead of an owned
String. Internally converts to String and delegates to new().
§Arguments
name- String slice containing the algorithm name
§Returns
Ok(Algorithm)- Successfully validated algorithmErr(PipelineError::InvalidConfiguration)- Name validation failed
§Errors
See Algorithm::new for validation rules and error conditions.
§Examples
Sourcepub fn is_compression(&self) -> bool
pub fn is_compression(&self) -> bool
Checks if this is a compression algorithm
§Purpose
Determines whether the algorithm belongs to the compression category. Used for algorithm validation and compatibility checks.
§Why
Compression algorithms require specific stage configurations and have different performance characteristics than encryption or hashing algorithms. # Returns
true- Algorithm is one of: brotli, gzip, zstd, lz4, deflatefalse- Algorithm is not a compression algorithm
§Examples
Sourcepub fn is_encryption(&self) -> bool
pub fn is_encryption(&self) -> bool
Checks if this is an encryption algorithm
§Purpose
Determines whether the algorithm belongs to the encryption category. Used for security validation and stage compatibility checks.
§Why
Encryption algorithms require key management and have different security properties than compression or hashing algorithms.
§Returns
true- Algorithm is one of: aes-256-gcm, aes-128-gcm, aes-128-cbc, chacha20-poly1305, aes-256-cbcfalse- Algorithm is not an encryption algorithm
§Examples
Sourcepub fn is_hashing(&self) -> bool
pub fn is_hashing(&self) -> bool
Checks if this is a hashing algorithm
§Purpose
Determines whether the algorithm belongs to the hashing category. Used for integrity validation and stage compatibility checks.
§Why
Hashing algorithms are one-way functions used for integrity verification, with different properties than compression or encryption algorithms. # Returns
true- Algorithm is one of: sha256, sha512, sha3-256, blake3, md5, sha1false- Algorithm is not a hashing algorithm
§Note
MD5 and SHA1 are included for backward compatibility but are not recommended for security-critical applications.
§Examples
Sourcepub fn is_custom(&self) -> bool
pub fn is_custom(&self) -> bool
Checks if this is a custom algorithm
§Purpose
Determines whether the algorithm is a custom (user-defined) algorithm that doesn’t match any of the predefined categories.
§Why
Custom algorithms allow extensibility for domain-specific processing while maintaining type safety and validation.
§Returns
true- Algorithm starts with “custom-” prefix OR doesn’t match any predefined compression, encryption, or hashing algorithmfalse- Algorithm is a predefined standard algorithm
§Examples
Sourcepub fn category(&self) -> AlgorithmCategory
pub fn category(&self) -> AlgorithmCategory
Gets the algorithm category
§Purpose
Classifies the algorithm into one of the predefined categories. Used for compatibility validation and processing stage selection.
§Returns
One of:
AlgorithmCategory::Compression- For compression algorithmsAlgorithmCategory::Encryption- For encryption algorithmsAlgorithmCategory::Hashing- For hashing algorithmsAlgorithmCategory::Custom- For custom/unknown algorithms
§Examples
Sourcepub fn validate(&self) -> Result<(), PipelineError>
pub fn validate(&self) -> Result<(), PipelineError>
Validates the algorithm
§Purpose
Re-validates the algorithm name format. Useful for ensuring algorithm integrity after deserialization or when working with external data.
§Why
While algorithms are validated on creation, this method allows revalidation after deserialization or when algorithm constraints change. # Returns
Ok(())- Algorithm name is validErr(PipelineError::InvalidConfiguration)- Name validation failed
§Errors
See Algorithm::new for validation rules and error conditions.
§Examples
Source§impl Algorithm
Predefined algorithms for common use cases
impl Algorithm
Predefined algorithms for common use cases
Sourcepub fn aes_256_gcm() -> Self
pub fn aes_256_gcm() -> Self
Sourcepub fn chacha20_poly1305() -> Self
pub fn chacha20_poly1305() -> Self
Sourcepub fn aes256_gcm() -> Self
pub fn aes256_gcm() -> Self
AES-256-GCM encryption algorithm (alias for test framework compatibility)
Sourcepub fn aes_128_cbc() -> Self
pub fn aes_128_cbc() -> Self
AES-128-CBC encryption
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Algorithm
impl<'de> Deserialize<'de> for Algorithm
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 Ord for Algorithm
impl Ord for Algorithm
Source§impl PartialOrd for Algorithm
impl PartialOrd for Algorithm
impl Eq for Algorithm
impl StructuralPartialEq for Algorithm
Auto Trait Implementations§
impl Freeze for Algorithm
impl RefUnwindSafe for Algorithm
impl Send for Algorithm
impl Sync for Algorithm
impl Unpin for Algorithm
impl UnwindSafe for Algorithm
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