Skip to content

Commit

Permalink
add test case for 4 byte utf8 codec
Browse files Browse the repository at this point in the history
  • Loading branch information
xemwebe committed Jul 17, 2023
1 parent 3dd8ece commit 282baa5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
3 changes: 0 additions & 3 deletions pkcs12/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ readme = "README.md"
edition = "2021"
rust-version = "1.65"

[features]
alloc = []

[dependencies]
cfg-if = "1.0.0"
digest = { version = "0.10.7", features=["alloc"] }
Expand Down
2 changes: 1 addition & 1 deletion pkcs12/src/kdf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Implementation of the key derivation function
//! [RFC 7292 Appendix B](https://datatracker.ietf.org/doc/html/rfc7292#appendix-B)

use alloc::vec::Vec;
use alloc::{vec, vec::Vec};
use digest::{core_api::BlockSizeUser, Digest, FixedOutputReset, OutputSizeUser, Update};
use zeroize::Zeroize;

Expand Down
26 changes: 21 additions & 5 deletions pkcs12/tests/kdf.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#![cfg(feature = "alloc")]

/// Test cases for the key derivation functions.
/// All test cases have been verified against openssl's method `PKCS12_key_gen_utf8`.
/// See https://github.com/xemwebe/test_pkcs12_kdf for a sample program.
///

use hex_literal::hex;
use pkcs12::kdf::{derive_key, Pkcs12KeyType};

#[test]
fn pkcs12_key_derive_sha256() {
use hex_literal::hex;
use pkcs12::kdf::{derive_key, Pkcs12KeyType};

const PASS_SHORT: &str = "ge@äheim";
const SALT_INC: [u8; 8] = [0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8];

Expand Down Expand Up @@ -123,3 +126,16 @@ fn pkcs12_key_derive_whirlpool() {
hex!("3324282adb468bff0734d3b7e399094ec8500cb5b0a3604055da107577aaf766")
);
}

#[test]
fn pkcs12_key_derive_special_chars() {
const PASS_SHORT: &str = "🔥";
const SALT_INC: [u8; 8] = [0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8];

assert_eq!(
derive_key::<sha2::Sha256>(PASS_SHORT, &SALT_INC, Pkcs12KeyType::EncryptionKey, 100, 32),
hex!("d01e72a940b4b1a7a5707fc8264a60cb7606ff9051dedff90930687d2513c006")
);
}


0 comments on commit 282baa5

Please sign in to comment.