feat(hash):完成基本散列算法。
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
pub mod md5 {
|
||||
use md5::Digest;
|
||||
pub fn hash<T: AsRef<[u8]>>(input: T) -> String {
|
||||
let mut hasher = md5::Md5::new();
|
||||
hasher.update(input);
|
||||
let result = hasher.finalize();
|
||||
crate::serialize::to_hex(result.as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
pub mod sha1 {
|
||||
use sha1::Digest;
|
||||
pub fn hash<T: AsRef<[u8]>>(input: T) -> String {
|
||||
let mut hasher = sha1::Sha1::new();
|
||||
hasher.update(input);
|
||||
let result = hasher.finalize();
|
||||
crate::serialize::to_hex(result.as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
pub mod sha512 {
|
||||
pub fn hash<T: AsRef<[u8]>>(input: T) -> String {
|
||||
let mut hasher = hmac_sha512::Hash::new();
|
||||
hasher.update(input);
|
||||
let result = hasher.finalize();
|
||||
crate::serialize::to_hex(result.as_slice())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
pub mod uuid {
|
||||
pub fn new() -> Box<String> {
|
||||
Box::from(uuid::Uuid::new_v4().to_string())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user