aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2022-10-09 19:41:15 +0200
committerAndreas Grois <andi@grois.info>2022-10-09 19:41:15 +0200
commit5e2f651400971d610ef76918e6f6366b01071e60 (patch)
treedd892ee718270dd6753b67fc69f27aeaea1858b4
parentfd68c7ad50b78f84443e826fbe29bce24c417dd7 (diff)
Add first integration test.
-rw-r--r--Cargo.toml8
-rw-r--r--tests/password_generation.rs76
2 files changed, 83 insertions, 1 deletions
diff --git a/Cargo.toml b/Cargo.toml
index c1090ce..e1ad2e3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,4 +16,10 @@ unicode-segmentation = "1.10.0"
[dev-dependencies]
strum = "0.24"
-strum_macros = "0.24" \ No newline at end of file
+strum_macros = "0.24"
+digest = "0.10.5"
+md4 = "0.10.2"
+md-5 = "0.10.5"
+sha-1 = "0.10.0"
+sha2 = "0.10.6"
+ripemd = "0.1.3" \ No newline at end of file
diff --git a/tests/password_generation.rs b/tests/password_generation.rs
new file mode 100644
index 0000000..45c6afa
--- /dev/null
+++ b/tests/password_generation.rs
@@ -0,0 +1,76 @@
+use passwordmaker_rs::{PasswordMaker, Hasher, HasherList, HashAlgorithm};
+use digest::Digest;
+use md4;
+use md5;
+use sha1;
+use sha2;
+use ripemd;
+
+struct Md4;
+struct Md5;
+struct Sha1;
+struct Sha256;
+struct RipeMD160;
+impl Hasher for Md4{
+ type Output = [u8;16];
+ fn hash(data : &[u8]) -> Self::Output {
+ md4::Md4::digest(data).into()
+ }
+}
+impl Hasher for Md5{
+ type Output = [u8;16];
+ fn hash(data : &[u8]) -> Self::Output {
+ md5::Md5::digest(data).into()
+ }
+}
+impl Hasher for Sha1{
+ type Output = [u8;20];
+ fn hash(data : &[u8]) -> Self::Output {
+ sha1::Sha1::digest(data).into()
+ }
+}
+impl Hasher for Sha256{
+ type Output = [u8;32];
+ fn hash(data : &[u8]) -> Self::Output {
+ sha2::Sha256::digest(data).into()
+ }
+}
+impl Hasher for RipeMD160{
+ type Output = [u8;20];
+ fn hash(data : &[u8]) -> Self::Output {
+ ripemd::Ripemd160::digest(data).into()
+ }
+}
+
+impl passwordmaker_rs::Md4 for Md4{}
+impl passwordmaker_rs::Md5 for Md5{}
+impl passwordmaker_rs::Sha1 for Sha1{}
+impl passwordmaker_rs::Sha256 for Sha256{}
+impl passwordmaker_rs::Ripemd160 for RipeMD160{}
+
+struct Hashes{}
+impl HasherList for Hashes {
+ type MD4 = Md4;
+ type MD5 = Md5;
+ type SHA1 = Sha1;
+ type SHA256 = Sha256;
+ type RIPEMD160 = RipeMD160;
+}
+
+type Pwm<'a> = PasswordMaker<'a, Hashes>;
+
+#[test]
+fn default_settings() {
+ let pwm = Pwm::new(
+ HashAlgorithm::Md5,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
+ "",
+ "",
+ 8,
+ "",
+ ""
+ ).unwrap();
+ let result = pwm.generate(".abcdefghij".to_owned(), "1".to_owned()).unwrap();
+ assert_eq!(result, "J3>'1F\"/");
+} \ No newline at end of file