Headers viewer

This commit is contained in:
Matéo Duparc 2021-06-30 15:24:15 +02:00
parent 18b0818ee4
commit 7cf87d5fa4
Signed by: hardcoresushi
GPG Key ID: 007F84120107191E
2 changed files with 40 additions and 3 deletions

24
src/bin/headers.rs Normal file
View File

@ -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<String> = 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(())
}

View File

@ -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 num_enum::TryFromPrimitive;
use chacha20::XChaCha20; use chacha20::XChaCha20;
use aes::{Aes256Ctr, cipher::{NewCipher, StreamCipher}}; 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)] #[derive(Debug, PartialEq, Eq)]
pub struct EncryptionParams { pub struct EncryptionParams {
password_salt: [u8; SALT_LEN], password_salt: [u8; SALT_LEN],
argon2: ArgonParams, pub argon2: ArgonParams,
hkdf_salt: [u8; SALT_LEN], hkdf_salt: [u8; SALT_LEN],
nonce: Vec<u8>, nonce: Vec<u8>,
cipher: CipherAlgorithm, pub cipher: CipherAlgorithm,
} }
impl EncryptionParams { impl EncryptionParams {