From 86e4c76dabb20b7f489abcb1f1c3cdb11a494b91 Mon Sep 17 00:00:00 2001 From: KunoiSayami <46131041+KunoiSayami@users.noreply.github.com> Date: Sat, 8 May 2021 01:22:08 +0800 Subject: fix: Fix authenticate-cookie not working properly * feat: Add adduser subcommand --- src/datastructures.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/datastructures.rs') diff --git a/src/datastructures.rs b/src/datastructures.rs index 6897bd3..b920eb4 100644 --- a/src/datastructures.rs +++ b/src/datastructures.rs @@ -28,6 +28,7 @@ use std::fs::read_to_string; const DEFAULT_CONFIG_LOCATION: &str = "/etc/cgitrc"; const DEFAULT_COOKIE_TTL: u64 = 1200; const DEFAULT_DATABASE_LOCATION: &str = "/etc/cgit/auth.db"; +pub const CACHE_DIR: &str = "/var/cache/cgit"; #[derive(Debug, Clone)] pub struct Config { @@ -97,6 +98,12 @@ impl FormData { Self { ..Default::default()} } + pub fn get_string_sha256_value(s: &str) -> Result { + let mut hasher = sha2::Sha256::new(); + hasher.update(s.as_bytes()); + Ok(format!("{:x}", hasher.finalize())) + } + pub fn set_password(&mut self, password: String) { self.password = password; self.hash = Default::default(); @@ -111,18 +118,21 @@ impl FormData { } pub fn get_password_sha256(&self) -> Result { - let mut hasher = sha2::Sha256::new(); - hasher.update(self.password.as_bytes()); - Ok(format!("{:x}", hasher.finalize())) + Self::get_string_sha256_value(&self.password) } #[allow(dead_code)] pub fn get_password_sha256_cache(&mut self) -> Result { - if self.hash.len() == 0 { + if self.hash.is_empty() { self.hash = self.get_password_sha256()?; } Ok(self.hash.clone()) } + + #[allow(dead_code)] + pub fn get_sha256_without_calc(&self) -> &String { + &self.hash + } } impl From<&[u8]> for FormData { -- cgit v1.3.1