pub struct HashAlgorithmWrapper { /* private fields */ }
Expand description
Universal wrapper for hash algorithms.
哈希算法的通用包装器。
§Purpose | 目的
This wrapper provides a unified interface for all hash algorithms, allowing runtime algorithm selection while maintaining type safety. It acts as a bridge between algorithm enums and concrete implementations.
此包装器为所有哈希算法提供统一接口, 允许运行时算法选择同时保持类型安全。它充当算法枚举和具体实现之间的桥梁。
§Features | 特性
-
Runtime Polymorphism: Switch between algorithms at runtime
-
Unified Interface: Same API for all hash algorithms
-
运行时多态性: 在运行时切换算法
-
统一接口: 所有哈希算法的相同 API
§Examples | 示例
use seal_crypto_wrapper::algorithms::hash::HashAlgorithm;
use seal_crypto_wrapper::wrappers::hash::HashAlgorithmWrapper;
// Create from algorithm enum
let algorithm = HashAlgorithm::build().sha256();
let wrapper = HashAlgorithmWrapper::from_enum(algorithm);
// Use unified interface
let digest = wrapper.hash(b"Hello, World!");
Implementations§
Source§impl HashAlgorithmWrapper
impl HashAlgorithmWrapper
Sourcepub fn new(algorithm: Box<dyn HashAlgorithmTrait>) -> Self
pub fn new(algorithm: Box<dyn HashAlgorithmTrait>) -> Self
Creates a new wrapper from a boxed trait object.
从 boxed trait 对象创建新的包装器。
This constructor allows you to wrap any implementation of
HashAlgorithmTrait
in the universal wrapper interface.
此构造函数允许您将 HashAlgorithmTrait
的任何实现
包装在通用包装器接口中。
§Arguments | 参数
-
algorithm
- A boxed trait object implementing the hash algorithm -
algorithm
- 实现哈希算法的 boxed trait 对象
Sourcepub fn from_enum(algorithm: HashAlgorithm) -> Self
pub fn from_enum(algorithm: HashAlgorithm) -> Self
Creates a wrapper from a hash algorithm enum.
从哈希算法枚举创建包装器。
This is the most common way to create a wrapper, as it automatically selects the appropriate concrete implementation based on the algorithm.
这是创建包装器的最常见方式,因为它根据算法自动选择适当的具体实现。
§Arguments | 参数
-
algorithm
- The hash algorithm enum variant -
algorithm
- 哈希算法枚举变体
§Examples | 示例
use seal_crypto_wrapper::algorithms::hash::HashAlgorithm;
use seal_crypto_wrapper::wrappers::hash::HashAlgorithmWrapper;
let sha256 = HashAlgorithmWrapper::from_enum(
HashAlgorithm::build().sha256()
);
let sha512 = HashAlgorithmWrapper::from_enum(
HashAlgorithm::build().sha512()
);
Trait Implementations§
Source§impl Clone for HashAlgorithmWrapper
impl Clone for HashAlgorithmWrapper
Source§fn clone(&self) -> HashAlgorithmWrapper
fn clone(&self) -> HashAlgorithmWrapper
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more