-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3bc3800
commit 131ffd0
Showing
5 changed files
with
50 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
use crate::error::{ApiError, ApiResult}; | ||
|
||
#[derive(Debug)] | ||
pub struct Secret { | ||
inner: String, | ||
} | ||
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord)] | ||
pub struct Secret(String); | ||
|
||
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, Eq, PartialEq, PartialOrd, Ord)] | ||
pub struct SecretHash(String); | ||
|
||
impl Secret { | ||
pub fn new(secret: String) -> Self { | ||
Self { inner: secret } | ||
Self(secret) | ||
} | ||
|
||
pub fn check(&self, hash: &str) -> Result<(), argon2::password_hash::Error> { | ||
crate::util::hash::argon_verify(&self.inner, hash) | ||
pub fn verify(&self, hash: &SecretHash) -> Result<(), argon2::password_hash::Error> { | ||
crate::util::hash::argon_verify(&self.0, &hash.0) | ||
} | ||
|
||
pub fn hash(&self) -> ApiResult<String> { | ||
crate::util::hash::argon_hash(&self.inner).map_err(|e| ApiError::HashError(e.to_string())) | ||
pub fn hash(&self) -> ApiResult<SecretHash> { | ||
crate::util::hash::argon_hash(&self.0) | ||
.map_err(|e| ApiError::HashError(e.to_string())) | ||
.map(|hash| SecretHash(hash)) | ||
} | ||
} |