From 663933e32ccb5d5aef3b383b43401ecff5042e98 Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Thu, 8 Jul 2021 18:10:16 +0200 Subject: [PATCH] Improve Argon2 parameters tests --- tests/cli.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/cli.rs b/tests/cli.rs index e35e6db..a355202 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -1,4 +1,4 @@ -use std::{io::{self, Read, Write}, fs::{self, File, create_dir}, path::PathBuf}; +use std::{convert::TryInto, fs::{self, File, create_dir}, io::{self, Read, Write}, path::PathBuf}; use assert_cmd::{Command, cargo::{CargoError, cargo_bin}}; use tempfile::TempDir; use doby::crypto::{CipherAlgorithm, SALT_LEN, HASH_LEN}; @@ -133,5 +133,11 @@ fn argon2_params() -> io::Result<()> { Command::cargo_bin("doby").unwrap().arg("-i").arg("0").assert().failure().stderr("Invalid argon2 params: time cost is too small\n"); Command::cargo_bin("doby").unwrap().arg("-m").arg("0").assert().failure().stderr("Invalid argon2 params: memory cost is too small\n"); Command::cargo_bin("doby").unwrap().arg("-t").arg("0").assert().failure().stderr("Invalid argon2 params: too few lanes\n"); + + let ciphertext = doby_cmd().unwrap().arg("-i").arg("8").arg("-m").arg("2048").arg("-t").arg("8").assert().success().stderr("").get_output().stdout.clone(); + assert_eq!(u32::from_be_bytes(ciphertext[4+SALT_LEN..4+SALT_LEN+4].try_into().unwrap()), 8); //time cost + assert_eq!(u32::from_be_bytes(ciphertext[4+SALT_LEN+4..4+SALT_LEN+8].try_into().unwrap()), 2048); //memory cost + assert_eq!(u8::from_be_bytes([ciphertext[4+SALT_LEN+8]]), 8); //parallelism + Ok(()) } \ No newline at end of file