Crates.io | secwords |
lib.rs | secwords |
version | 2.1.1 |
source | src |
created_at | 2021-08-31 08:56:27.613851 |
updated_at | 2021-09-07 04:21:12.150921 |
description | secure and safe password container. |
homepage | https://github.com/just-do-halee/secwords |
repository | https://github.com/just-do-halee/secwords |
max_upload_size | |
id | 444944 |
size | 28,503 |
Secwords
secure and safe password container.
| Docs | Latest Note |
[dependencies]
secwords = "2.1.1"
or
[dependencies]
secwords = { version = "2.1.1", default-features = false } # no-std
How to
use secwords::Password;
use sha2::Sha256; // can be any hasher of dyn Digest `digest` crate
let plain = String::from("pa5$wOrs"); // <- example
let pass1 = Password::<Sha256, 6>::new(plain).unwrap(); // min length = 6
let pass2: Password<Sha256, 6> = "pa5$wOrs".parse().unwrap();
assert_eq!(pass1, pass2); // they are hashed, original is gone(safely)
assert_eq!(pass1.len(), 32); // fixed size `vep`(crate)
assert_eq!(pass1.as_ref(), pass2.as_slice());
assert_eq!(pass1.to_vec(), pass2.to_vec());
assert_eq!(pass1, "pa5$wOrs");
assert_eq!(pass1, String::from("pa5$wOrs"));
assert_eq!(&pass1.to_hex().unwrap()[..20], "0f521249b366dd6e0acc");
assert_eq!(format!("{}", pass1), "***SECURE***"); // display
assert_eq!(format!("{:?}", pass1), "***SECURE***"); // debug
let bytes = pass1.to_bytes(); // encode
let pass3 = Password::<Sha256, 6>::from_bytes(bytes).unwrap(); // decode
assert_eq!(pass1, pass3);
let hex_string = pass1.to_hex().unwrap(); // encode
let pass3 = Password::<Sha256, 6>::from_hex(hex_string).unwrap(); // decode
assert_eq!(pass1, pass3);
there are more examples in the lib.rs