From b760560b1ad33414624ed5c11f18dca78a2bf51a Mon Sep 17 00:00:00 2001 From: EETagent Date: Fri, 28 Oct 2022 14:41:07 +0200 Subject: [PATCH] refactor: use std:Error or compatible type in crypto.rs --- core/Cargo.toml | 6 +++--- core/src/crypto.rs | 16 ++++++---------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/core/Cargo.toml b/core/Cargo.toml index 33a247d..67be561 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -14,9 +14,9 @@ tokio = "1.21.2" futures = "0.3.25" # crypto -argon2 = "0.4.1" -age = { version = "0.9.0", features = ["async"] } -base64 = "0.13.1" +argon2 = { version = "0.4", features = ["std"] } +age = { version = "0.9", features = ["async"] } +base64 = "0.13" [dependencies.sea-orm] version = "^0.10.0" diff --git a/core/src/crypto.rs b/core/src/crypto.rs index c227b43..16d2c3b 100644 --- a/core/src/crypto.rs +++ b/core/src/crypto.rs @@ -30,7 +30,7 @@ pub fn random_8_char_string() -> String { // TODO: No unwrap for spawn_blocking pub async fn hash_password( password_plain_text: String, -) -> Result { +) -> Result> { let argon_config = Argon2::default(); let hash = tokio::task::spawn_blocking(move || { @@ -40,19 +40,16 @@ pub async fn hash_password( let encrypted = argon_config.hash_password(password, salt); encrypted }) - .await - .unwrap(); + .await??; - let result = hash?; - - return Ok(result.to_string()); + return Ok(hash.to_string()); } // TODO: No unwrap for spawn_blocking pub async fn verify_password<'a>( password_plaint_text: String, hash: String, -) -> Result { +) -> Result> { let argon_config = Argon2::default(); let result: Result = @@ -67,10 +64,9 @@ pub async fn verify_password<'a>( Err(error) => return Err(error), } }) - .await - .unwrap(); + .await?; - result + Ok(result?) } pub async fn encrypt_password(