From 5bdf8d0f2d024e17ba2275b2698f1d61365a4c6c Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 10 Feb 2024 12:50:25 +0000 Subject: [PATCH] Add newtype for padlock generation secret --- src/auth.rs | 8 +++++--- src/secrets.rs | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/auth.rs b/src/auth.rs index 9406335..8d584a3 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -7,7 +7,7 @@ use rand::{ distributions::{Alphanumeric, DistString}, thread_rng, }; -use secrecy::{ExposeSecret, SecretVec}; +use secrecy::ExposeSecret; use thiserror::Error; use time::{macros::format_description, OffsetDateTime}; use tokio::sync::Mutex; @@ -15,7 +15,9 @@ use tracing::{event, instrument, Level}; use crate::{ db::{/* Database, */ Database, SqliteDatabase}, - secrets::{Password, ServerHash, ServerPadlock, UserServerKey, UserToken}, + secrets::{ + PadlockGenerationSecret, Password, ServerHash, ServerPadlock, UserServerKey, UserToken, + }, }; #[derive(Debug, Error)] @@ -75,7 +77,7 @@ impl UserAuthenticator { } pub struct ServerPadlockGenerator { - secret: SecretVec, + secret: PadlockGenerationSecret, } impl ServerPadlockGenerator { diff --git a/src/secrets.rs b/src/secrets.rs index 6db2f96..1c5aa31 100644 --- a/src/secrets.rs +++ b/src/secrets.rs @@ -1,4 +1,6 @@ -use secrecy::SecretString; +use std::fmt::Debug; + +use secrecy::{ExposeSecret, SecretString, SecretVec}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Deserialize)] @@ -35,3 +37,17 @@ impl From for ServerPadlock { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ServerHash(pub Vec); + +pub struct PadlockGenerationSecret(pub SecretVec); +impl Debug for PadlockGenerationSecret { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_tuple("PadlockGenerationSecret") + .field(&"[REDACTED Vec]") + .finish() + } +} +impl Clone for PadlockGenerationSecret { + fn clone(&self) -> Self { + PadlockGenerationSecret(self.0.expose_secret().clone().into()) + } +}