Add newtype for padlock generation secret

This commit is contained in:
Xiretza 2024-02-10 12:50:25 +00:00
parent 3657d83bd1
commit 5bdf8d0f2d
2 changed files with 22 additions and 4 deletions

View file

@ -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<u8>,
secret: PadlockGenerationSecret,
}
impl ServerPadlockGenerator {

View file

@ -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<String> for ServerPadlock {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServerHash(pub Vec<u8>);
pub struct PadlockGenerationSecret(pub SecretVec<u8>);
impl Debug for PadlockGenerationSecret {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("PadlockGenerationSecret")
.field(&"[REDACTED Vec<u8>]")
.finish()
}
}
impl Clone for PadlockGenerationSecret {
fn clone(&self) -> Self {
PadlockGenerationSecret(self.0.expose_secret().clone().into())
}
}