From c6406ea0eddc9a02a844c2f8ebc60ebc03e0faa8 Mon Sep 17 00:00:00 2001 From: KunoiSayami Date: Tue, 28 Mar 2023 19:43:54 +0800 Subject: chore(dep): Upgrade crate library Signed-off-by: KunoiSayami --- src/datastructures.rs | 32 +++++++++++++++++++------------- src/main.rs | 2 +- src/test.rs | 16 +++++++++------- 3 files changed, 29 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/datastructures.rs b/src/datastructures.rs index 736fe67..29c852c 100644 --- a/src/datastructures.rs +++ b/src/datastructures.rs @@ -20,6 +20,7 @@ use argon2::{ password_hash::{rand_core::OsRng, PasswordHash, PasswordHasher, PasswordVerifier, SaltString}, Argon2, }; +use base64::Engine; #[cfg(feature = "pam")] pub use ds_pam::*; use log::error; @@ -119,6 +120,12 @@ pub mod ds_pam { provider: String, } + impl PAMAuthorizer { + pub fn provider(&self) -> &str { + &self.provider + } + } + impl From<&PAMConfig> for PAMAuthorizer { fn from(cfg: &PAMConfig) -> Self { Self { @@ -501,10 +508,7 @@ impl FormData { let argon2_alg = Argon2::default(); - Ok(argon2_alg - .hash_password(passwd, salt.as_ref()) - .unwrap() - .to_string()) + Ok(argon2_alg.hash_password(passwd, &salt).unwrap().to_string()) } pub fn set_password(&mut self, password: String) { @@ -512,7 +516,7 @@ impl FormData { self.hash = Default::default(); } - pub async fn authorize(&self, authorizer: &Box) -> anyhow::Result { + pub async fn authorize(&self, authorizer: &Box) -> Result { authorizer.verify(&self.user, &self.password).await } @@ -585,7 +589,9 @@ impl Cookie { for cookie in cookies.split(';').map(|x| x.trim()) { let (key, value) = cookie.split_once('=').unwrap(); if key.eq("cgit_auth") { - let value = base64::decode(value).unwrap_or_default(); + let value = base64::engine::general_purpose::STANDARD + .decode(value) + .unwrap_or_default(); let value = std::str::from_utf8(&value).unwrap_or(""); if !value.contains(';') { @@ -637,7 +643,7 @@ impl std::fmt::Display for Cookie { "{}_{}; {}; {}", self.timestamp, self.randint, self.user, self.reversed ); - write!(f, "{}", base64::encode(s)) + write!(f, "{}", base64::engine::general_purpose::STANDARD.encode(s)) } } @@ -667,7 +673,7 @@ pub trait Authorizer { fn method(&self) -> AuthorizerType { AuthorizerType::Password } - async fn verify(&self, name: &str, password: &str) -> anyhow::Result; + async fn verify(&self, name: &str, password: &str) -> Result; } #[async_trait::async_trait] @@ -679,7 +685,7 @@ where (**self).method() } - async fn verify(&self, user: &str, password: &str) -> anyhow::Result { + async fn verify(&self, user: &str, password: &str) -> Result { (**self).verify(user, password).await } } @@ -719,8 +725,8 @@ impl Authorizer for PAMAuthorizer { AuthorizerType::PAM } - async fn verify(&self, user: &str, password: &str) -> anyhow::Result { - let service = self.provider.as_str(); + async fn verify(&self, user: &str, password: &str) -> Result { + let service = self.provider(); let mut auth = pam::Authenticator::with_password(service).unwrap(); auth.get_handler() @@ -748,7 +754,7 @@ impl From<&Config> for SQLAuthorizer { } impl WrapConfigure { - pub(crate) async fn hook(&self) -> anyhow::Result<()> { + pub(crate) async fn hook(&self) -> Result<()> { let cfg = &self.config; if !cfg.get_test_status() { let last_copied = cfg.get_last_copy_timestamp().await.unwrap_or(0); @@ -775,7 +781,7 @@ impl WrapConfigure { #[async_trait::async_trait] impl Authorizer for SQLAuthorizer { - async fn verify(&self, user: &str, password: &str) -> anyhow::Result { + async fn verify(&self, user: &str, password: &str) -> Result { let mut conn = sqlx::sqlite::SqliteConnectOptions::from_str(self.database_location.as_str())? .journal_mode(sqlx::sqlite::SqliteJournalMode::Off) diff --git a/src/main.rs b/src/main.rs index c8eff4b..de94789 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ /* - ** Copyright (C) 2021-2022-2022 KunoiSayami + ** Copyright (C) 2021-2023 KunoiSayami ** ** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU Affero General Public License as published by diff --git a/src/test.rs b/src/test.rs index 1a377ae..7a92407 100644 --- a/src/test.rs +++ b/src/test.rs @@ -17,9 +17,11 @@ #[cfg(test)] mod core { - use crate::datastructures::{rand_str, Config, TestSuite}; - use crate::{cmd_add_user, cmd_authenticate_cookie, cmd_init, cmd_repo_user_control}; - use crate::{get_arg_matches, IOModule}; + use crate::{ + cmd_add_user, cmd_authenticate_cookie, cmd_init, cmd_repo_user_control, + datastructures::{rand_str, Config, TestSuite}, + get_arg_matches, IOModule, + }; use argon2::{ password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString}, Argon2, @@ -41,7 +43,7 @@ mod core { let argon2 = Argon2::default(); - argon2.hash_password(passwd, salt.as_ref()).unwrap(); + argon2.hash_password(passwd, &salt).unwrap(); } #[test] @@ -141,7 +143,7 @@ mod core { std::fs::File::create("test/DATABASE_INITED").unwrap(); } - fn lock(path: &std::path::PathBuf, sleep_length: usize) { + fn lock(path: &PathBuf, sleep_length: usize) { for _ in 0..(sleep_length * 100) { sleep(Duration::from_millis(10)); if path.exists() { @@ -157,7 +159,7 @@ mod core { #[test] fn test_02_insert_user() { lock(&PathBuf::from("test/DATABASE_INITED"), 3); - let matches = crate::get_arg_matches(Some(vec!["a", "user", "add", "hunter2", "hunter2"])); + let matches = get_arg_matches(Some(vec!["a", "user", "add", "hunter2", "hunter2"])); match matches.subcommand() { Some(("user", matches)) => match matches.subcommand() { Some(("add", matches)) => { @@ -184,7 +186,7 @@ mod core { vec!["a", "repo", "add", "repo", "hunter"], ]; for x in args { - let matches = crate::get_arg_matches(Some(x)); + let matches = get_arg_matches(Some(x)); match matches.subcommand() { Some(("repo", matches)) => match matches.subcommand() { Some(("add", matches)) => { -- cgit v1.3.1