diff --git a/src/algorithm.rs b/src/algorithm.rs index 053c853..e490b91 100644 --- a/src/algorithm.rs +++ b/src/algorithm.rs @@ -21,7 +21,7 @@ impl Algorithm { impl Default for Algorithm { fn default() -> Self { - Self::Rsa2048Sha256 + crate::DEFAULT_CNF_ALGORITHM } } diff --git a/src/canonicalization.rs b/src/canonicalization.rs index b90460e..e943a21 100644 --- a/src/canonicalization.rs +++ b/src/canonicalization.rs @@ -6,12 +6,6 @@ pub enum CanonicalizationType { Simple, } -impl Default for CanonicalizationType { - fn default() -> Self { - Self::Relaxed - } -} - impl ToString for CanonicalizationType { fn to_string(&self) -> String { match self { @@ -33,7 +27,7 @@ impl FromStr for CanonicalizationType { } } -#[derive(Clone, Copy, Debug, Default)] +#[derive(Clone, Copy, Debug)] pub struct Canonicalization { header_alg: CanonicalizationType, body_alg: CanonicalizationType, @@ -65,6 +59,15 @@ impl Canonicalization { } } +impl Default for Canonicalization { + fn default() -> Self { + Self { + header_alg: crate::DEFAULT_CNF_CANONICALIZATION_HEADER, + body_alg: crate::DEFAULT_CNF_CANONICALIZATION_BODY, + } + } +} + impl ToString for Canonicalization { fn to_string(&self) -> String { format!( diff --git a/src/config.rs b/src/config.rs index 769c149..dd659ea 100644 --- a/src/config.rs +++ b/src/config.rs @@ -26,15 +26,15 @@ pub struct Config { header: Vec, #[arg(short = 'o', long)] header_optional: Vec, - #[arg(short = 'p', long, default_value_t = NonZeroU64::new(15552000).unwrap())] + #[arg(short = 'p', long, default_value_t = NonZeroU64::new(crate::DEFAULT_CNF_CRYPTOPERIOD).unwrap())] cryptoperiod: NonZeroU64, - #[arg(short, long, default_value_t = 1728000)] + #[arg(short, long, default_value_t = crate::DEFAULT_CNF_REVOCATION)] revocation: u64, #[arg(short = 'u', long)] dns_update_cmd: String, #[arg(short, long, action = clap::ArgAction::Count)] verbose: u8, - #[arg(short = 'x', long, default_value_t = 1296000)] + #[arg(short = 'x', long, default_value_t = crate::DEFAULT_CNF_EXPIRATION)] expiration: u64, } @@ -43,8 +43,8 @@ impl Config { let mut cnf = Self::parse(); cnf.key_data_base = process_key_data_base(cnf.key_data_base); cnf.domain = process_domains(&cnf.domain, &cnf.domain_file)?; - cnf.header = process_headers(&cnf.header, crate::DEFAULT_HEADERS); - cnf.header_optional = process_headers(&cnf.header_optional, crate::DEFAULT_HEADERS_OPT); + cnf.header = process_headers(&cnf.header, crate::DEFAULT_CNF_HEADERS); + cnf.header_optional = process_headers(&cnf.header_optional, crate::DEFAULT_CNF_HEADERS_OPT); Ok(cnf) } @@ -107,9 +107,11 @@ impl Config { fn process_key_data_base(opt: Option) -> Option { match opt { Some(p) => Some(p), - None => Some(PathBuf::from( - "/var/lib/opensmtpd-filter-dkimout/key-db.sqlite3", - )), + None => { + let mut path = PathBuf::from(crate::DEFAULT_LIB_DIR); + path.push(crate::DEFAULT_CNF_KEY_DB); + Some(path) + } } } diff --git a/src/main.rs b/src/main.rs index 3cc5909..e5c5f04 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,14 +7,24 @@ mod logs; mod message; mod stdin_reader; +use algorithm::Algorithm; +use canonicalization::CanonicalizationType; use entry::Entry; use message::Message; use std::collections::HashMap; use stdin_reader::StdinReader; const DEFAULT_BUFF_SIZE: usize = 1024; -const DEFAULT_HEADERS: &str = "from:reply-to:subject:date:to:cc"; -const DEFAULT_HEADERS_OPT: &str = "resent-date:resent-from:resent-to:resent-cc:in-reply-to:references:list-id:list-help:list-unsubscribe:list-subscribe:list-post:list-owner:list-archive"; +const DEFAULT_CNF_ALGORITHM: Algorithm = Algorithm::Rsa2048Sha256; +const DEFAULT_CNF_CANONICALIZATION_BODY: CanonicalizationType = CanonicalizationType::Relaxed; +const DEFAULT_CNF_CANONICALIZATION_HEADER: CanonicalizationType = CanonicalizationType::Relaxed; +const DEFAULT_CNF_CRYPTOPERIOD: u64 = 15552000; +const DEFAULT_CNF_EXPIRATION: u64 = 1296000; +const DEFAULT_CNF_HEADERS: &str = "from:reply-to:subject:date:to:cc"; +const DEFAULT_CNF_HEADERS_OPT: &str = "resent-date:resent-from:resent-to:resent-cc:in-reply-to:references:list-id:list-help:list-unsubscribe:list-subscribe:list-post:list-owner:list-archive"; +const DEFAULT_CNF_KEY_DB: &str = "key-db.sqlite3"; +const DEFAULT_CNF_REVOCATION: u64 = 1728000; +const DEFAULT_LIB_DIR: &str = "/var/lib/opensmtpd-filter-dkimout"; const DEFAULT_MSG_SIZE: usize = 1024 * 1024; const LOG_LEVEL_ENV_VAR: &str = "OPENSMTPD_FILTER_DKIMOUT_LOG_LEVEL";