#[repr(u16)]pub enum HashAlgo {
Md5 = 0,
Sha256 = 1,
Other = 255,
}
Expand description
Supported various hash algorithms.
This enum defines the supported hash algorithms, each represented by a specific
identifier (u16 value). The available algorithms include Md5
, Sha256
, and Other
for unspecified or custom algorithms.
§Variants
Md5
: MD5 hash algorithm (0x00).Sha256
: SHA-256 hash algorithm (0x01).Other
: Represents other custom or unsupported hash algorithms (0xFF).
§Example
use amebazii::types::enums::HashAlgo;
let algo = HashAlgo::try_from(1).unwrap();
assert_eq!(algo, HashAlgo::Sha256); // Successfully converts to Sha256.
Variants§
Implementations§
Source§impl HashAlgo
impl HashAlgo
Sourcepub fn compute_hash(
&self,
buffer: &[u8],
key: Option<&[u8]>,
) -> Result<Vec<u8>, Error>
pub fn compute_hash( &self, buffer: &[u8], key: Option<&[u8]>, ) -> Result<Vec<u8>, Error>
Computes the hash of the provided buffer using the specified algorithm.
If a key is provided, HMAC (Hash-based Message Authentication Code) is used.
§Parameters
buffer
: A byte slice containing the data to be hashed.key
: An optional byte slice containing the key for HMAC. IfNone
, the raw hash is computed.
§Returns
Ok(Vec<u8>)
: The computed hash as a vector of bytes.Err(Error::UnsupportedHashAlgo)
: An error if an unsupported hash algorithm is chosen.
§Example
use amebazii::types::enums::HashAlgo;
let data = b"some data to hash";
let algo = HashAlgo::Md5;
let result = algo.compute_hash(data, None).unwrap();
assert_eq!(result.len(), 16); // MD5 produces a 16-byte hash.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for HashAlgo
impl<'de> Deserialize<'de> for HashAlgo
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for HashAlgo
impl Ord for HashAlgo
Source§impl PartialOrd for HashAlgo
impl PartialOrd for HashAlgo
Source§impl TryFrom<u16> for HashAlgo
impl TryFrom<u16> for HashAlgo
Source§fn try_from(value: u16) -> Result<Self, Self::Error>
fn try_from(value: u16) -> Result<Self, Self::Error>
Tries to convert a u16
value to a corresponding HashAlgo
variant.
§Parameters
value
: Theu16
value representing the hash algorithm.
§Returns
Ok(HashAlgo)
: The correspondingHashAlgo
variant if the value matches.Err(Error::InvalidEnumValue)
: An error if the value doesn’t match a valid hash algorithm.
impl Copy for HashAlgo
impl Eq for HashAlgo
impl StructuralPartialEq for HashAlgo
Auto Trait Implementations§
impl Freeze for HashAlgo
impl RefUnwindSafe for HashAlgo
impl Send for HashAlgo
impl Sync for HashAlgo
impl Unpin for HashAlgo
impl UnwindSafe for HashAlgo
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
Mutably borrows from an owned value. Read more