1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-20 00:15:17 +00:00

Update sha1

This commit is contained in:
2022-03-09 19:07:22 +01:00
parent a16bbc3249
commit ae546b2d3e
3 changed files with 52 additions and 7 deletions

View File

@ -4,9 +4,11 @@
extern crate sha1;
use crate::data::error::{ResultBoxError, ExecError};
use rand::{thread_rng, Rng};
use rand::{Rng, thread_rng};
use rand::distributions::Alphanumeric;
use sha1::Digest;
use crate::data::error::{ExecError, ResultBoxError};
/// Generate a new sha1 string
///
@ -17,7 +19,10 @@ use rand::distributions::Alphanumeric;
/// assert_eq!(res, "e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4");
/// ```
pub fn sha1_str(input: &str) -> String {
sha1::Sha1::from(input).digest().to_string()
let mut hasher = sha1::Sha1::default();
hasher.update(input.as_bytes());
let result = hasher.finalize();
format!("{:x}", result)
}
/// One-way user password crypt