diff --git a/src/bin/headers.rs b/src/bin/headers.rs new file mode 100644 index 0000000..8cf73e9 --- /dev/null +++ b/src/bin/headers.rs @@ -0,0 +1,24 @@ +use std::{env, fs::File, io::{self, Read}}; +use doby::{MAGIC_BYTES, crypto::EncryptionParams}; + +fn main() -> io::Result<()> { + let args: Vec = env::args().collect(); + let mut file = File::open(&args[1])?; + + let mut magic_bytes = vec![0; MAGIC_BYTES.len()]; + file.read(&mut magic_bytes)?; + if magic_bytes == MAGIC_BYTES { + match EncryptionParams::read(&mut file)? { + Some(params) => { + println!("Argon2 time cost: {}", params.argon2.t_cost); + println!("Argon2 memory cost: {}KB", params.argon2.m_cost); + println!("Argon2 parallelism: {}", params.argon2.parallelism); + println!("Encryption cihpher: {}", params.cipher); + } + None => eprintln!("Invalid cipher") + } + } else { + eprintln!("Doby format not recognized."); + } + Ok(()) +} \ No newline at end of file diff --git a/src/crypto.rs b/src/crypto.rs index 3cac5b5..ae2e022 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -1,4 +1,8 @@ -use std::{convert::TryFrom, io::{self, Read, Write}}; +use std::{ + convert::TryFrom, + fmt::{self, Display, Formatter}, + io::{self, Read, Write} +}; use num_enum::TryFromPrimitive; use chacha20::XChaCha20; use aes::{Aes256Ctr, cipher::{NewCipher, StreamCipher}}; @@ -37,13 +41,22 @@ impl CipherAlgorithm { } } +impl Display for CipherAlgorithm { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str(match self { + CipherAlgorithm::AesCtr => "AES-CTR", + CipherAlgorithm::XChaCha20 => "XChaCha20", + }) + } +} + #[derive(Debug, PartialEq, Eq)] pub struct EncryptionParams { password_salt: [u8; SALT_LEN], - argon2: ArgonParams, + pub argon2: ArgonParams, hkdf_salt: [u8; SALT_LEN], nonce: Vec, - cipher: CipherAlgorithm, + pub cipher: CipherAlgorithm, } impl EncryptionParams {