diff options
Diffstat (limited to 'vendor/commoncrypto/tests')
-rw-r--r-- | vendor/commoncrypto/tests/hash.rs | 18 | ||||
-rw-r--r-- | vendor/commoncrypto/tests/pbkdf2.rs | 16 |
2 files changed, 34 insertions, 0 deletions
diff --git a/vendor/commoncrypto/tests/hash.rs b/vendor/commoncrypto/tests/hash.rs new file mode 100644 index 0000000..bccc86c --- /dev/null +++ b/vendor/commoncrypto/tests/hash.rs @@ -0,0 +1,18 @@ +extern crate commoncrypto; +extern crate hex; + +use commoncrypto::hash::{CCDigestAlgorithm, Hasher}; +use hex::ToHex; +use std::io::Write; + +const TO_HASH: &'static str = "The quick brown fox jumps over the lazy dog"; +const TO_HASH_MD5: &'static str = "9e107d9d372bb6826bd81d3542a419d6"; + +#[test] +fn md5_hasher() { + let mut hasher = Hasher::new(CCDigestAlgorithm::kCCDigestMD5); + assert!(hasher.write_all(TO_HASH.as_bytes()).is_ok()); + let result = hasher.finish(); + assert!(result.is_ok()); + assert_eq!(result.expect("Hash failed").to_hex(), TO_HASH_MD5) +} diff --git a/vendor/commoncrypto/tests/pbkdf2.rs b/vendor/commoncrypto/tests/pbkdf2.rs new file mode 100644 index 0000000..179c5ae --- /dev/null +++ b/vendor/commoncrypto/tests/pbkdf2.rs @@ -0,0 +1,16 @@ +extern crate commoncrypto; +extern crate hex; + +use commoncrypto::pbkdf2::{pbkdf2, CCPseudoRandomAlgorithm}; +use hex::ToHex; + +#[test] +fn derive_pbkdf2() { + let derived = pbkdf2(b"password", + b"salt", + CCPseudoRandomAlgorithm::kCCPRFHmacAlgSHA1, + 1, + 20) + .unwrap(); + assert_eq!("0c60c80f961f0e71f3a9b524af6012062fe037a6", derived.to_hex()); +} |