Algorithm

Struct Algorithm 

Source
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: Algorithm struct with same interface
  • JSON: String representation
  • SQLite: TEXT column with validation

§Examples

Implementations§

Source§

impl Algorithm

Source

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 algorithm
  • Err(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
Source

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 algorithm
  • Err(PipelineError::InvalidConfiguration) - Name validation failed
§Errors

See Algorithm::new for validation rules and error conditions.

§Examples
Source

pub fn name(&self) -> &str

Gets the algorithm name as a string reference

§Purpose

Provides read-only access to the algorithm’s underlying name string.

§Returns

String slice containing the algorithm name

§Examples
Source

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, deflate
  • false - Algorithm is not a compression algorithm
§Examples
Source

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-cbc
  • false - Algorithm is not an encryption algorithm
§Examples
Source

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, sha1
  • false - Algorithm is not a hashing algorithm
§Note

MD5 and SHA1 are included for backward compatibility but are not recommended for security-critical applications.

§Examples
Source

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 algorithm
  • false - Algorithm is a predefined standard algorithm
§Examples
Source

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 algorithms
  • AlgorithmCategory::Encryption - For encryption algorithms
  • AlgorithmCategory::Hashing - For hashing algorithms
  • AlgorithmCategory::Custom - For custom/unknown algorithms
§Examples
Source

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 valid
  • Err(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

Source

pub fn brotli() -> Self

Creates a Brotli compression algorithm

§Purpose

Factory method for the Brotli compression algorithm. Brotli offers excellent compression ratios with good performance.

§Returns

Validated Algorithm instance for Brotli

§Examples
Source

pub fn gzip() -> Self

Creates a Gzip compression algorithm

§Purpose

Factory method for the Gzip compression algorithm. Widely supported compression with balanced performance.

§Returns

Validated Algorithm instance for Gzip

§Examples
Source

pub fn zstd() -> Self

Creates a Zstandard compression algorithm

§Purpose

Factory method for the Zstandard compression algorithm. Excellent balance of compression ratio and speed.

§Returns

Validated Algorithm instance for Zstandard

§Examples
Source

pub fn lz4() -> Self

Creates an LZ4 compression algorithm

§Purpose

Factory method for the LZ4 compression algorithm. Extremely fast compression with moderate compression ratios.

§Returns

Validated Algorithm instance for LZ4

§Examples
Source

pub fn aes_256_gcm() -> Self

Creates an AES-256-GCM encryption algorithm

§Purpose

Factory method for AES-256 with Galois/Counter Mode. Provides authenticated encryption with strong security.

§Returns

Validated Algorithm instance for AES-256-GCM

§Examples
Source

pub fn chacha20_poly1305() -> Self

Creates a ChaCha20-Poly1305 encryption algorithm

§Purpose

Factory method for ChaCha20 stream cipher with Poly1305 MAC. Modern authenticated encryption with excellent performance on mobile/embedded. # Returns Validated Algorithm instance for ChaCha20-Poly1305

§Examples
Source

pub fn sha256() -> Self

Creates a SHA-256 hashing algorithm

§Purpose

Factory method for SHA-256 cryptographic hash function. Industry-standard hashing for integrity verification.

§Returns

Validated Algorithm instance for SHA-256

§Examples
Source

pub fn sha512() -> Self

Creates a SHA-512 hashing algorithm

§Purpose

Factory method for SHA-512 cryptographic hash function. Stronger variant of SHA-2 family with 512-bit output.

§Returns

Validated Algorithm instance for SHA-512

§Examples
Source

pub fn blake3() -> Self

Creates a BLAKE3 hashing algorithm

§Purpose

Factory method for BLAKE3 cryptographic hash function. Modern, high-performance hashing with strong security properties.

§Returns

Validated Algorithm instance for BLAKE3

§Examples
Source

pub fn aes256_gcm() -> Self

AES-256-GCM encryption algorithm (alias for test framework compatibility)

Source

pub fn none() -> Self

No algorithm / passthrough

Source

pub fn aes_128_cbc() -> Self

AES-128-CBC encryption

Source

pub fn sha3_256() -> Self

SHA3-256 hashing

Trait Implementations§

Source§

impl AsRef<str> for Algorithm

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Algorithm

Source§

fn clone(&self) -> Algorithm

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Algorithm

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Algorithm

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Algorithm

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Algorithm> for String

Source§

fn from(algorithm: Algorithm) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Algorithm

Source§

type Err = PipelineError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Algorithm

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Algorithm

Source§

fn cmp(&self, other: &Algorithm) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Algorithm

Source§

fn eq(&self, other: &Algorithm) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Algorithm

Source§

fn partial_cmp(&self, other: &Algorithm) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Algorithm

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Algorithm

Source§

impl StructuralPartialEq for Algorithm

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,