diff --git a/backend/src/confirmation.rs b/backend/src/confirmation.rs index 08d52e7..27f5010 100644 --- a/backend/src/confirmation.rs +++ b/backend/src/confirmation.rs @@ -5,8 +5,8 @@ use log::{debug, error, warn}; use crate::errors::SpecialErrors; use crate::management::{delete_key, Action, Pending}; use crate::settings::{MAILER, SETTINGS}; -use crate::utils::{get_email_from_cert, insert_key, parse_pem, read_file}; -use crate::{log_err, pending_path, validate_cert}; +use crate::utils::{get_email_from_cert, insert_key, parse_pem, read_file, validate_cert}; +use crate::{log_err, pending_path}; use anyhow::Result; use lettre::{AsyncTransport, Message}; @@ -25,7 +25,7 @@ pub fn confirm_action(token: &str) -> Result<(Action, String)> { let address = match key.action() { Action::Add => { let cert = parse_pem(key.data())?; - let validcert = validate_cert!(cert)?; + let validcert = validate_cert(&cert)?; let email = get_email_from_cert(&validcert)?; log_err!(insert_key(&validcert), warn)?; email diff --git a/backend/src/main.rs b/backend/src/main.rs index 0d4b886..5aab3b7 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -11,7 +11,7 @@ use crate::management::{clean_stale, store_pending_addition, store_pending_delet use crate::settings::{ROOT_FOLDER, SETTINGS}; use crate::utils::{ gen_random_token, get_email_from_cert, is_email_allowed, key_exists, parse_pem, read_file, - return_outcome, + return_outcome, validate_cert }; use actix_files::Files; @@ -102,7 +102,7 @@ async fn index(req: HttpRequest) -> Result { #[post("/api/submit")] async fn submit(pem: web::Form) -> Result { let cert = parse_pem(&pem.key)?; - let validcert = validate_cert!(cert)?; + let validcert = validate_cert(&cert)?; if validcert.is_tsk() { Err(SpecialErrors::ContainsSecret)? } diff --git a/backend/src/utils.rs b/backend/src/utils.rs index 05d8fa6..b07a8ca 100644 --- a/backend/src/utils.rs +++ b/backend/src/utils.rs @@ -24,14 +24,11 @@ use std::{ path::{Path, PathBuf}, }; -#[macro_export] -macro_rules! validate_cert { - ( $x:expr ) => { - match log_err!($x.with_policy($crate::settings::POLICY, None), debug) { - Ok(validcert) => Ok(validcert), - Err(_) => Err($crate::errors::SpecialErrors::InvalidCert), - } - }; +pub fn validate_cert(cert: &Cert) -> Result { + match log_err!(cert.with_policy(crate::settings::POLICY, None), debug) { + Ok(validcert) => Ok(validcert), + Err(_) => Err(SpecialErrors::InvalidCert)?, + } } pub fn encode_local(local: &str) -> String { @@ -106,7 +103,7 @@ pub fn parse_pem(pemfile: &str) -> Result { Ok(cert) => cert, Err(_) => Err(SpecialErrors::MalformedCert)?, }; - validate_cert!(cert)?; + validate_cert(&cert)?; Ok(cert) }