diff --git a/src/classes.rs b/src/classes.rs index 239034a..3298e90 100644 --- a/src/classes.rs +++ b/src/classes.rs @@ -39,7 +39,7 @@ pub enum HashAlgorithm { #[derive(Debug, Copy, Clone, PartialEq, Eq, EnumString)] #[strum(ascii_case_insensitive)] -pub enum ValueEncoding { +pub enum OutputEncoding { Hex, Base64, Base32, diff --git a/src/hasher.rs b/src/hasher.rs index d8a250c..a4abe81 100644 --- a/src/hasher.rs +++ b/src/hasher.rs @@ -1,4 +1,4 @@ -use crate::classes::{BasicHash, ValueEncoding}; +use crate::classes::{BasicHash, OutputEncoding}; use byteorder::{BigEndian, ByteOrder}; use data_encoding::{BASE32, BASE64}; use digest::{Digest, Output}; @@ -55,19 +55,20 @@ fn hash_file_whole(filename: &str) -> anyhow::Result> { #[inline] pub fn hash_file_encoded( filename: &str, - encoding: ValueEncoding, + output_encoding: OutputEncoding, ) -> anyhow::Result { let h = hash_file::(filename)?; - let encoded = match encoding { - ValueEncoding::Hex => hex::encode(h), - ValueEncoding::Base64 => BASE64.encode(&h), - ValueEncoding::Base32 => BASE32.encode(&h), + let encoded = match output_encoding { + OutputEncoding::Hex => hex::encode(h), + OutputEncoding::Base64 => BASE64.encode(&h), + OutputEncoding::Base32 => BASE32.encode(&h), }; Ok(BasicHash(encoded)) } +/// Hash a file using CRC32, and return the result as a `BasicHash` u32 #[inline] pub fn hash_file_u32(filename: &str) -> anyhow::Result { let h = hash_file::(filename)?; diff --git a/src/main.rs b/src/main.rs index fefe3c8..465e5b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use crate::classes::{ }; //use crate::hasher::hash_file_crc32; use blake2::{Blake2b512, Blake2s256}; -use classes::ValueEncoding; +use classes::OutputEncoding; use glob::GlobResult; use hasher::{file_exists, hash_file_encoded, hash_file_u32}; use md5::Md5; @@ -240,22 +240,22 @@ fn call_hasher(algo: HashAlgorithm, path: &str) -> anyhow::Result { // special case, u32 encoded HashAlgorithm::CRC32 => hash_file_u32::(path), // old algorithms - HashAlgorithm::MD5 => hash_file_encoded::(path, ValueEncoding::Hex), - HashAlgorithm::SHA1 => hash_file_encoded::(path, ValueEncoding::Hex), + HashAlgorithm::MD5 => hash_file_encoded::(path, OutputEncoding::Hex), + HashAlgorithm::SHA1 => hash_file_encoded::(path, OutputEncoding::Hex), // SHA2 - HashAlgorithm::SHA2_224 => hash_file_encoded::(path, ValueEncoding::Hex), - HashAlgorithm::SHA2_256 => hash_file_encoded::(path, ValueEncoding::Hex), - HashAlgorithm::SHA2_384 => hash_file_encoded::(path, ValueEncoding::Hex), - HashAlgorithm::SHA2_512 => hash_file_encoded::(path, ValueEncoding::Hex), + HashAlgorithm::SHA2_224 => hash_file_encoded::(path, OutputEncoding::Hex), + HashAlgorithm::SHA2_256 => hash_file_encoded::(path, OutputEncoding::Hex), + HashAlgorithm::SHA2_384 => hash_file_encoded::(path, OutputEncoding::Hex), + HashAlgorithm::SHA2_512 => hash_file_encoded::(path, OutputEncoding::Hex), // SHA3 - HashAlgorithm::SHA3_256 => hash_file_encoded::(path, ValueEncoding::Hex), - HashAlgorithm::SHA3_384 => hash_file_encoded::(path, ValueEncoding::Hex), - HashAlgorithm::SHA3_512 => hash_file_encoded::(path, ValueEncoding::Hex), + HashAlgorithm::SHA3_256 => hash_file_encoded::(path, OutputEncoding::Hex), + HashAlgorithm::SHA3_384 => hash_file_encoded::(path, OutputEncoding::Hex), + HashAlgorithm::SHA3_512 => hash_file_encoded::(path, OutputEncoding::Hex), // WHIRLPOOL - HashAlgorithm::Whirlpool => hash_file_encoded::(path, ValueEncoding::Hex), + HashAlgorithm::Whirlpool => hash_file_encoded::(path, OutputEncoding::Hex), // BLAKE2 - HashAlgorithm::Blake2S256 => hash_file_encoded::(path, ValueEncoding::Hex), - HashAlgorithm::Blake2B512 => hash_file_encoded::(path, ValueEncoding::Hex), + HashAlgorithm::Blake2S256 => hash_file_encoded::(path, OutputEncoding::Hex), + HashAlgorithm::Blake2B512 => hash_file_encoded::(path, OutputEncoding::Hex), } }