From e4aa6c190918a6e7cd57ef88a8e546d97cb0a25b Mon Sep 17 00:00:00 2001 From: DenebTM Date: Sat, 10 Feb 2024 12:30:04 +0100 Subject: [PATCH] impl From for {Password,UserToken} --- src/auth.rs | 10 ++++++++++ src/db.rs | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/auth.rs b/src/auth.rs index a16cc27..cd79d0d 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -8,9 +8,19 @@ use tracing::instrument; use crate::db::{Database, SqliteDatabase}; #[derive(Debug, Clone, Deserialize)] pub struct Password(pub SecretString); +impl From for Password { + fn from(value: String) -> Self { + Self(SecretString::new(value)) + } +} #[derive(Debug, Clone, Deserialize)] pub struct UserToken(pub SecretString); +impl From for UserToken { + fn from(value: String) -> Self { + Self(SecretString::new(value)) + } +} #[derive(Debug)] pub struct Authenticator { diff --git a/src/db.rs b/src/db.rs index 4606fec..045bcd1 100644 --- a/src/db.rs +++ b/src/db.rs @@ -59,6 +59,6 @@ impl Database for SqliteDatabase { .fetch_one(&mut self.conn) .await?; - Ok(UserToken(SecretString::new(row.0))) + Ok(UserToken::from(row.0)) } }