X-Git-Url: https://code.octet-stream.net/hashgood/blobdiff_plain/1dec1ec82f55d639d9fad0d0933545aa509c4272..2d750bf20797d9f7eaf838296ac878f97f6b6846:/src/main.rs?ds=sidebyside diff --git a/src/main.rs b/src/main.rs index 2f1e7f3..2c7e189 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ mod verify; #[structopt(name = "hashgood")] pub struct Opt { /// Read the hash from the clipboard + #[cfg(feature = "paste")] #[structopt(short = "p", long = "paste")] paste: bool, @@ -36,6 +37,19 @@ pub struct Opt { hash: Option, } +impl Opt { + fn get_paste(&self) -> bool { + #[cfg(feature = "paste")] + { + return self.paste; + } + #[cfg(not(feature = "paste"))] + { + return false; + } + } +} + /// Types of supported digest algorithm #[derive(Debug, PartialEq, Copy, Clone)] pub enum Algorithm { @@ -57,6 +71,7 @@ impl Algorithm { } /// The method by which one or more hashes were supplied to verify the calculated digest +#[derive(Debug, PartialEq)] pub enum VerificationSource { CommandArgument, Clipboard, @@ -88,6 +103,7 @@ impl Hash { } /// A possible hash to match against. The algorithm is assumed. +#[derive(Debug, PartialEq)] pub struct CandidateHash { bytes: Vec, filename: Option, @@ -95,6 +111,7 @@ pub struct CandidateHash { /// A list of candidate hashes that our input could potentially match. At this point it is /// assumed that we will be verifying a digest of a particular, single algorithm. +#[derive(Debug, PartialEq)] pub struct CandidateHashes { alg: Algorithm, hashes: Vec, @@ -179,12 +196,12 @@ fn hashgood() -> Result<(), Box> { fn get_verified_options() -> Result { let opt = Opt::from_args(); let hash_methods = - opt.hash.is_some() as i32 + opt.paste as i32 + opt.hash_file.is_some() as i32; + opt.hash.is_some() as i32 + opt.get_paste() as i32 + opt.hash_file.is_some() as i32; if hash_methods > 1 { if opt.hash.is_some() { eprintln!("* specified as command line argument"); } - if opt.paste { + if opt.get_paste() { eprintln!("* paste from clipboard (-p)") } if opt.hash_file.is_some() {