From 961b01ffd65a95eee5b17f73101bc28ea6d101f3 Mon Sep 17 00:00:00 2001 From: rasul Date: Tue, 28 Apr 2020 08:27:44 -0500 Subject: [PATCH] return Result for errors --- src/password.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/password.rs b/src/password.rs index d76a38f..89e77c7 100644 --- a/src/password.rs +++ b/src/password.rs @@ -8,6 +8,8 @@ use rusqlite::Row; use serde_derive::{Deserialize, Serialize}; use crate::hash::{hash, salt}; +use crate::result::RudeResult; +use crate::try_log; /// Containing object for the password #[derive(Clone, Debug, Deserialize, Serialize)] @@ -21,19 +23,22 @@ pub struct Password { impl Password { /// Create a new password object from a string password. - pub fn new>(s: S) -> Self { + pub fn new>(s: S) -> RudeResult { let salt = salt(); - let hash = hash(s, &salt); + let hash = try_log!(hash(s, &salt), "Unable to create hash"); - Self { salt, hash } + Ok(Self { salt, hash }) } /// Check the password against the provided password. - pub fn check>(&self, s: S) -> bool { + pub fn check>(&self, s: S) -> RudeResult { let s = s.into(); - let hash = hash(s, &self.salt); + let hash = try_log!( + hash(s, &self.salt), + "Unable to check hash", + ); - self.hash == hash + Ok(self.hash == hash) } }