Struct HashAlgorithmWrapper

Source
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

Source

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 对象

Source

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

Source§

fn clone(&self) -> HashAlgorithmWrapper

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 HashAlgorithmWrapper

Source§

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

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

impl Deref for HashAlgorithmWrapper

Source§

type Target = Box<dyn HashAlgorithmTrait>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl From<Box<dyn HashAlgorithmTrait>> for HashAlgorithmWrapper

Source§

fn from(algorithm: Box<dyn HashAlgorithmTrait>) -> Self

Converts to this type from the input type.
Source§

impl From<HashAlgorithm> for HashAlgorithmWrapper

Source§

fn from(algorithm: HashAlgorithm) -> Self

Converts to this type from the input type.
Source§

impl HashAlgorithmTrait for HashAlgorithmWrapper

Source§

fn hash(&self, data: &[u8]) -> Vec<u8>

Hashes the given data. Read more
Source§

fn hmac(&self, key: &[u8], msg: &[u8]) -> Result<Vec<u8>>

Computes the HMAC of a message using the given key. Read more
Source§

fn algorithm(&self) -> HashAlgorithm

Returns the algorithm enum. Read more
Source§

fn clone_box(&self) -> Box<dyn HashAlgorithmTrait>

Clones the algorithm. Read more
Source§

fn into_boxed(self) -> Box<dyn HashAlgorithmTrait>

Source§

impl Into<Box<dyn HashAlgorithmTrait>> for HashAlgorithmWrapper

Source§

fn into(self) -> Box<dyn HashAlgorithmTrait>

Converts this type into the (usually inferred) input type.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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, 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