pub enum Algorithm {
SHA1,
SHA256,
SHA512,
}Expand description
Enum representing the supported hashing algorithms.
§Variants
SHA1- Represents the SHA-1 hashing algorithm.SHA256- Represents the SHA-256 hashing algorithm.SHA512- Represents the SHA-512 hashing algorithm.
Variants§
Trait Implementations§
Source§impl AlgorithmTrait for Algorithm
impl AlgorithmTrait for Algorithm
Source§fn from_string(name: String) -> Option<Self>
fn from_string(name: String) -> Option<Self>
Creates an Algorithm instance from its string representation.
§Arguments
name- AStringrepresenting the algorithm name (e.g.,"SHA1","SHA256", or"SHA512").
§Returns
An Option<Algorithm> corresponding to the string. Returns None if the string does not match any supported algorithm.
§Example
use rusotp::{Algorithm, AlgorithmTrait};
let algo = Algorithm::from_string("SHA256".to_string());
assert_eq!(algo, Some(Algorithm::SHA256));Source§fn hash(&self, secret: Vec<u8>, data: u64) -> Result<Vec<u8>, String>
fn hash(&self, secret: Vec<u8>, data: u64) -> Result<Vec<u8>, String>
Hashes the given secret and data using the selected algorithm.
§Arguments
secret- AVec<u8>representing the shared secret key.data- Au64value representing the data to be hashed.
§Returns
A Result containing a Vec<u8> with the hashed value if successful, or a String with the error message if the hashing process fails.
§Errors
Returns an error if the HMAC construction or finalization fails.
§Example
use rusotp::{Algorithm, AlgorithmTrait};
let secret = vec![1, 2, 3, 4, 5, 6, 7, 8];
let data = 123456u64;
let algo = Algorithm::SHA256;
let result = algo.hash(secret, data);
assert!(result.is_ok());impl Copy 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
Mutably borrows from an owned value. Read more
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>
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 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>
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