diff --git a/src/algorithm.rs b/src/algorithm.rs new file mode 100644 index 0000000..d84fc1e --- /dev/null +++ b/src/algorithm.rs @@ -0,0 +1,40 @@ +use std::str::FromStr; + +#[derive(Clone, Copy, Debug)] +pub enum Algorithm { + Ed25519Sha256, + Rsa2048Sha256, + Rsa3072Sha256, + Rsa4096Sha256, +} + +impl Default for Algorithm { + fn default() -> Self { + Self::Ed25519Sha256 + } +} + +impl ToString for Algorithm { + fn to_string(&self) -> String { + match self { + Self::Ed25519Sha256 => String::from("ed25519-sha256"), + Self::Rsa2048Sha256 => String::from("rsa2048-sha256"), + Self::Rsa3072Sha256 => String::from("rsa3072-sha256"), + Self::Rsa4096Sha256 => String::from("rsa4096-sha256"), + } + } +} + +impl FromStr for Algorithm { + type Err = String; + + fn from_str(s: &str) -> Result { + match s.to_lowercase().as_str() { + "ed25519-sha256" => Ok(Self::Ed25519Sha256), + "rsa2048-sha256" => Ok(Self::Rsa2048Sha256), + "rsa3072-sha256" => Ok(Self::Rsa3072Sha256), + "rsa4096-sha256" => Ok(Self::Rsa4096Sha256), + _ => Err(format!("{s}: invalid signing algorithm")), + } + } +} diff --git a/src/config.rs b/src/config.rs index 7098bbf..492dbcc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,3 +1,4 @@ +use crate::algorithm::Algorithm; use crate::canonicalization::Canonicalization; use clap::Parser; use std::collections::HashSet; @@ -9,6 +10,8 @@ use std::path::PathBuf; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] pub struct Config { + #[arg(short, long, default_value_t = Algorithm::default())] + algorithm: Algorithm, #[arg(short, long, default_value_t = Canonicalization::default())] canonicalization: Canonicalization, #[arg(short, long)] @@ -37,6 +40,10 @@ impl Config { Ok(cnf) } + pub fn algorithm(&self) -> Algorithm { + self.algorithm + } + pub fn canonicalization(&self) -> Canonicalization { self.canonicalization } diff --git a/src/main.rs b/src/main.rs index cdb75a3..7418565 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +mod algorithm; mod canonicalization; mod config; mod entry;