From 853b760968cb6295ea1e1fc56eca6747f4724520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Berthaud-M=C3=BCller?= Date: Sat, 27 Mar 2021 13:31:14 -0400 Subject: [PATCH] secret as string and not bytes --- src/config.rs | 11 +---------- src/models/users.rs | 4 ++-- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/config.rs b/src/config.rs index f0e0428..e664e51 100644 --- a/src/config.rs +++ b/src/config.rs @@ -20,20 +20,11 @@ pub struct DnsConfig { #[derive(Debug, Deserialize)] pub struct WebAppConfig { - #[serde(deserialize_with = "from_base64")] - pub secret: Vec, + pub secret: String, #[serde(deserialize_with = "from_duration")] pub token_duration: Duration, } -fn from_base64<'de, D>(deserializer: D) -> Result, D::Error> - where D: Deserializer<'de> -{ - use serde::de::Error; - String::deserialize(deserializer) - .and_then(|string| base64::decode(&string).map_err(|err| Error::custom(err.to_string()))) -} - fn from_duration<'de, D>(deserializer: D) -> Result where D: Deserializer<'de> { diff --git a/src/models/users.rs b/src/models/users.rs index cd0989b..be1a6b7 100644 --- a/src/models/users.rs +++ b/src/models/users.rs @@ -200,7 +200,7 @@ impl AuthClaims { } } - pub fn encode(self, secret: &[u8]) -> JwtResult { - encode(&Header::default(), &self, &EncodingKey::from_secret(&secret)) + pub fn encode(self, secret: &str) -> JwtResult { + encode(&Header::default(), &self, &EncodingKey::from_secret(secret.as_bytes())) } }