mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-07 12:00:43 +00:00
refactor: use std:Error or compatible type in crypto.rs
This commit is contained in:
parent
a7251e668e
commit
b760560b1a
2 changed files with 9 additions and 13 deletions
|
|
@ -14,9 +14,9 @@ tokio = "1.21.2"
|
||||||
futures = "0.3.25"
|
futures = "0.3.25"
|
||||||
|
|
||||||
# crypto
|
# crypto
|
||||||
argon2 = "0.4.1"
|
argon2 = { version = "0.4", features = ["std"] }
|
||||||
age = { version = "0.9.0", features = ["async"] }
|
age = { version = "0.9", features = ["async"] }
|
||||||
base64 = "0.13.1"
|
base64 = "0.13"
|
||||||
|
|
||||||
[dependencies.sea-orm]
|
[dependencies.sea-orm]
|
||||||
version = "^0.10.0"
|
version = "^0.10.0"
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ pub fn random_8_char_string() -> String {
|
||||||
// TODO: No unwrap for spawn_blocking
|
// TODO: No unwrap for spawn_blocking
|
||||||
pub async fn hash_password(
|
pub async fn hash_password(
|
||||||
password_plain_text: String,
|
password_plain_text: String,
|
||||||
) -> Result<String, argon2::password_hash::Error> {
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
let argon_config = Argon2::default();
|
let argon_config = Argon2::default();
|
||||||
|
|
||||||
let hash = tokio::task::spawn_blocking(move || {
|
let hash = tokio::task::spawn_blocking(move || {
|
||||||
|
|
@ -40,19 +40,16 @@ pub async fn hash_password(
|
||||||
let encrypted = argon_config.hash_password(password, salt);
|
let encrypted = argon_config.hash_password(password, salt);
|
||||||
encrypted
|
encrypted
|
||||||
})
|
})
|
||||||
.await
|
.await??;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let result = hash?;
|
return Ok(hash.to_string());
|
||||||
|
|
||||||
return Ok(result.to_string());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: No unwrap for spawn_blocking
|
// TODO: No unwrap for spawn_blocking
|
||||||
pub async fn verify_password<'a>(
|
pub async fn verify_password<'a>(
|
||||||
password_plaint_text: String,
|
password_plaint_text: String,
|
||||||
hash: String,
|
hash: String,
|
||||||
) -> Result<bool, argon2::password_hash::Error> {
|
) -> Result<bool, Box<dyn std::error::Error>> {
|
||||||
let argon_config = Argon2::default();
|
let argon_config = Argon2::default();
|
||||||
|
|
||||||
let result: Result<bool, argon2::password_hash::Error> =
|
let result: Result<bool, argon2::password_hash::Error> =
|
||||||
|
|
@ -67,10 +64,9 @@ pub async fn verify_password<'a>(
|
||||||
Err(error) => return Err(error),
|
Err(error) => return Err(error),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
result
|
Ok(result?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn encrypt_password(
|
pub async fn encrypt_password(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue