Skip to content

Commit

Permalink
test: Add test data
Browse files Browse the repository at this point in the history
  • Loading branch information
sorairolake committed Dec 23, 2024
1 parent 1cf67fd commit 19e0d67
Show file tree
Hide file tree
Showing 34 changed files with 1,841 additions and 197 deletions.
2 changes: 1 addition & 1 deletion crates/abcrypt/benches/argon2_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use abcrypt::Argon2;
use test::Bencher;

// Generated using `abcrypt` crate version 0.4.0.
const TEST_DATA_ENC: &[u8] = include_bytes!("../tests/data/v1/data.txt.abcrypt");
const TEST_DATA_ENC: &[u8] = include_bytes!("../tests/data/v1/argon2id/v0x13/data.txt.abcrypt");

#[bench]
fn params(b: &mut Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion crates/abcrypt/benches/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use test::Bencher;

const PASSPHRASE: &str = "passphrase";
// Generated using `abcrypt` crate version 0.4.0.
const TEST_DATA_ENC: &[u8] = include_bytes!("../tests/data/v1/data.txt.abcrypt");
const TEST_DATA_ENC: &[u8] = include_bytes!("../tests/data/v1/argon2id/v0x13/data.txt.abcrypt");

#[bench]
fn decrypt(b: &mut Bencher) {
Expand Down
2 changes: 1 addition & 1 deletion crates/abcrypt/benches/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use abcrypt::Params;
use test::Bencher;

// Generated using `abcrypt` crate version 0.4.0.
const TEST_DATA_ENC: &[u8] = include_bytes!("../tests/data/v1/data.txt.abcrypt");
const TEST_DATA_ENC: &[u8] = include_bytes!("../tests/data/v1/argon2id/v0x13/data.txt.abcrypt");

#[bench]
fn params(b: &mut Bencher) {
Expand Down
6 changes: 3 additions & 3 deletions crates/abcrypt/src/argon2_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Argon2 {
/// ```
/// # use abcrypt::Argon2;
/// #
/// let ciphertext = include_bytes!("../tests/data/v1/data.txt.abcrypt");
/// let ciphertext = include_bytes!("../tests/data/v1/argon2id/v0x13/data.txt.abcrypt");
///
/// assert!(Argon2::new(ciphertext).is_ok());
/// ```
Expand All @@ -57,7 +57,7 @@ impl Argon2 {
/// ```
/// # use abcrypt::{argon2::Algorithm, Argon2};
/// #
/// let ciphertext = include_bytes!("../tests/data/v1/data.txt.abcrypt");
/// let ciphertext = include_bytes!("../tests/data/v1/argon2id/v0x13/data.txt.abcrypt");
///
/// let argon2 = Argon2::new(ciphertext).unwrap();
/// assert_eq!(argon2.variant(), Algorithm::Argon2id);
Expand All @@ -75,7 +75,7 @@ impl Argon2 {
/// ```
/// # use abcrypt::{argon2::Version, Argon2};
/// #
/// let ciphertext = include_bytes!("../tests/data/v1/data.txt.abcrypt");
/// let ciphertext = include_bytes!("../tests/data/v1/argon2id/v0x13/data.txt.abcrypt");
///
/// let argon2 = Argon2::new(ciphertext).unwrap();
/// assert_eq!(argon2.version(), Version::V0x13);
Expand Down
10 changes: 5 additions & 5 deletions crates/abcrypt/src/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'c> Decryptor<'c> {
/// ```
/// # use abcrypt::Decryptor;
/// #
/// let ciphertext = include_bytes!("../tests/data/v1/data.txt.abcrypt");
/// let ciphertext = include_bytes!("../tests/data/v1/argon2id/v0x13/data.txt.abcrypt");
/// let passphrase = "passphrase";
///
/// let cipher = Decryptor::new(&ciphertext, passphrase).unwrap();
Expand Down Expand Up @@ -109,7 +109,7 @@ impl<'c> Decryptor<'c> {
/// # use abcrypt::Decryptor;
/// #
/// let data = b"Hello, world!\n";
/// let ciphertext = include_bytes!("../tests/data/v1/data.txt.abcrypt");
/// let ciphertext = include_bytes!("../tests/data/v1/argon2id/v0x13/data.txt.abcrypt");
/// let passphrase = "passphrase";
///
/// let cipher = Decryptor::new(&ciphertext, passphrase).unwrap();
Expand Down Expand Up @@ -147,7 +147,7 @@ impl<'c> Decryptor<'c> {
/// # use abcrypt::Decryptor;
/// #
/// let data = b"Hello, world!\n";
/// let ciphertext = include_bytes!("../tests/data/v1/data.txt.abcrypt");
/// let ciphertext = include_bytes!("../tests/data/v1/argon2id/v0x13/data.txt.abcrypt");
/// let passphrase = "passphrase";
///
/// let cipher = Decryptor::new(&ciphertext, passphrase).unwrap();
Expand All @@ -169,7 +169,7 @@ impl<'c> Decryptor<'c> {
/// ```
/// # use abcrypt::Decryptor;
/// #
/// let ciphertext = include_bytes!("../tests/data/v1/data.txt.abcrypt");
/// let ciphertext = include_bytes!("../tests/data/v1/argon2id/v0x13/data.txt.abcrypt");
/// let passphrase = "passphrase";
///
/// let cipher = Decryptor::new(&ciphertext, passphrase).unwrap();
Expand Down Expand Up @@ -206,7 +206,7 @@ impl<'c> Decryptor<'c> {
///
/// ```
/// let data = b"Hello, world!\n";
/// let ciphertext = include_bytes!("../tests/data/v1/data.txt.abcrypt");
/// let ciphertext = include_bytes!("../tests/data/v1/argon2id/v0x13/data.txt.abcrypt");
/// let passphrase = "passphrase";
///
/// let plaintext = abcrypt::decrypt(ciphertext, passphrase).unwrap();
Expand Down
8 changes: 4 additions & 4 deletions crates/abcrypt/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Params {
/// ```
/// # use abcrypt::Params;
/// #
/// let ciphertext = include_bytes!("../tests/data/v1/data.txt.abcrypt");
/// let ciphertext = include_bytes!("../tests/data/v1/argon2id/v0x13/data.txt.abcrypt");
///
/// assert!(Params::new(ciphertext).is_ok());
/// ```
Expand All @@ -56,7 +56,7 @@ impl Params {
/// ```
/// # use abcrypt::Params;
/// #
/// let ciphertext = include_bytes!("../tests/data/v1/data.txt.abcrypt");
/// let ciphertext = include_bytes!("../tests/data/v1/argon2id/v0x13/data.txt.abcrypt");
///
/// let params = Params::new(ciphertext).unwrap();
/// assert_eq!(params.memory_cost(), 32);
Expand All @@ -74,7 +74,7 @@ impl Params {
/// ```
/// # use abcrypt::Params;
/// #
/// let ciphertext = include_bytes!("../tests/data/v1/data.txt.abcrypt");
/// let ciphertext = include_bytes!("../tests/data/v1/argon2id/v0x13/data.txt.abcrypt");
///
/// let params = Params::new(ciphertext).unwrap();
/// assert_eq!(params.time_cost(), 3);
Expand All @@ -92,7 +92,7 @@ impl Params {
/// ```
/// # use abcrypt::Params;
/// #
/// let ciphertext = include_bytes!("../tests/data/v1/data.txt.abcrypt");
/// let ciphertext = include_bytes!("../tests/data/v1/argon2id/v0x13/data.txt.abcrypt");
///
/// let params = Params::new(ciphertext).unwrap();
/// assert_eq!(params.parallelism(), 4);
Expand Down
56 changes: 51 additions & 5 deletions crates/abcrypt/tests/argon2_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use abcrypt::{
};

// Generated using `abcrypt` crate version 0.4.0.
const TEST_DATA_ENC: &[u8] = include_bytes!("data/v1/data.txt.abcrypt");
const TEST_DATA_ENC: &[u8] = include_bytes!("data/v1/argon2id/v0x13/data.txt.abcrypt");

#[test]
fn success() {
Expand All @@ -18,12 +18,58 @@ fn success() {

#[test]
fn variant() {
let argon2 = Argon2::new(TEST_DATA_ENC).unwrap();
assert_eq!(argon2.variant(), Algorithm::Argon2id);
{
let argon2 = Argon2::new(include_bytes!("data/v1/argon2d/v0x10/data.txt.abcrypt")).unwrap();
assert_eq!(argon2.variant(), Algorithm::Argon2d);
}
{
let argon2 = Argon2::new(include_bytes!("data/v1/argon2d/v0x13/data.txt.abcrypt")).unwrap();
assert_eq!(argon2.variant(), Algorithm::Argon2d);
}
{
let argon2 = Argon2::new(include_bytes!("data/v1/argon2i/v0x10/data.txt.abcrypt")).unwrap();
assert_eq!(argon2.variant(), Algorithm::Argon2i);
}
{
let argon2 = Argon2::new(include_bytes!("data/v1/argon2i/v0x13/data.txt.abcrypt")).unwrap();
assert_eq!(argon2.variant(), Algorithm::Argon2i);
}
{
let argon2 =
Argon2::new(include_bytes!("data/v1/argon2id/v0x10/data.txt.abcrypt")).unwrap();
assert_eq!(argon2.variant(), Algorithm::Argon2id);
}
{
let argon2 = Argon2::new(TEST_DATA_ENC).unwrap();
assert_eq!(argon2.variant(), Algorithm::Argon2id);
}
}

#[test]
fn version() {
let argon2 = Argon2::new(TEST_DATA_ENC).unwrap();
assert_eq!(argon2.version(), Version::V0x13);
{
let argon2 = Argon2::new(include_bytes!("data/v1/argon2d/v0x10/data.txt.abcrypt")).unwrap();
assert_eq!(argon2.version(), Version::V0x10);
}
{
let argon2 = Argon2::new(include_bytes!("data/v1/argon2d/v0x13/data.txt.abcrypt")).unwrap();
assert_eq!(argon2.version(), Version::V0x13);
}
{
let argon2 = Argon2::new(include_bytes!("data/v1/argon2i/v0x10/data.txt.abcrypt")).unwrap();
assert_eq!(argon2.version(), Version::V0x10);
}
{
let argon2 = Argon2::new(include_bytes!("data/v1/argon2i/v0x13/data.txt.abcrypt")).unwrap();
assert_eq!(argon2.version(), Version::V0x13);
}
{
let argon2 =
Argon2::new(include_bytes!("data/v1/argon2id/v0x10/data.txt.abcrypt")).unwrap();
assert_eq!(argon2.version(), Version::V0x10);
}
{
let argon2 = Argon2::new(TEST_DATA_ENC).unwrap();
assert_eq!(argon2.version(), Version::V0x13);
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 Shun Sakai

SPDX-License-Identifier: Apache-2.0 OR MIT
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 Shun Sakai

SPDX-License-Identifier: Apache-2.0 OR MIT
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 Shun Sakai

SPDX-License-Identifier: Apache-2.0 OR MIT
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 Shun Sakai

SPDX-License-Identifier: Apache-2.0 OR MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 Shun Sakai

SPDX-License-Identifier: Apache-2.0 OR MIT
67 changes: 62 additions & 5 deletions crates/abcrypt/tests/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,71 @@ use abcrypt::{
const PASSPHRASE: &str = "passphrase";
const TEST_DATA: &[u8] = include_bytes!("data/data.txt");
// Generated using `abcrypt` crate version 0.4.0.
const TEST_DATA_ENC: &[u8] = include_bytes!("data/v1/data.txt.abcrypt");
const TEST_DATA_ENC: &[u8] = include_bytes!("data/v1/argon2id/v0x13/data.txt.abcrypt");

#[test]
fn success() {
let cipher = Decryptor::new(&TEST_DATA_ENC, PASSPHRASE).unwrap();
let mut buf = [u8::default(); TEST_DATA.len()];
cipher.decrypt(&mut buf).unwrap();
assert_eq!(buf, TEST_DATA);
#[cfg(feature = "alloc")]
{
let cipher = Decryptor::new(
&include_bytes!("data/v1/argon2d/v0x10/data.txt.abcrypt"),
PASSPHRASE,
)
.unwrap();
let mut buf = [u8::default(); TEST_DATA.len()];
cipher.decrypt(&mut buf).unwrap();
assert_eq!(buf, TEST_DATA);
}
#[cfg(feature = "alloc")]
{
let cipher = Decryptor::new(
&include_bytes!("data/v1/argon2d/v0x13/data.txt.abcrypt"),
PASSPHRASE,
)
.unwrap();
let mut buf = [u8::default(); TEST_DATA.len()];
cipher.decrypt(&mut buf).unwrap();
assert_eq!(buf, TEST_DATA);
}
#[cfg(feature = "alloc")]
{
let cipher = Decryptor::new(
&include_bytes!("data/v1/argon2i/v0x10/data.txt.abcrypt"),
PASSPHRASE,
)
.unwrap();
let mut buf = [u8::default(); TEST_DATA.len()];
cipher.decrypt(&mut buf).unwrap();
assert_eq!(buf, TEST_DATA);
}
#[cfg(feature = "alloc")]
{
let cipher = Decryptor::new(
&include_bytes!("data/v1/argon2i/v0x13/data.txt.abcrypt"),
PASSPHRASE,
)
.unwrap();
let mut buf = [u8::default(); TEST_DATA.len()];
cipher.decrypt(&mut buf).unwrap();
assert_eq!(buf, TEST_DATA);
}
#[cfg(feature = "alloc")]
{
let cipher = Decryptor::new(
&include_bytes!("data/v1/argon2id/v0x10/data.txt.abcrypt"),
PASSPHRASE,
)
.unwrap();
let mut buf = [u8::default(); TEST_DATA.len()];
cipher.decrypt(&mut buf).unwrap();
assert_eq!(buf, TEST_DATA);
}
{
let cipher = Decryptor::new(&TEST_DATA_ENC, PASSPHRASE).unwrap();
let mut buf = [u8::default(); TEST_DATA.len()];
cipher.decrypt(&mut buf).unwrap();
assert_eq!(buf, TEST_DATA);
}
}

#[cfg(feature = "alloc")]
Expand Down
Loading

0 comments on commit 19e0d67

Please sign in to comment.