#![deny(unsafe_code)]
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
extern crate alloc;
mod password;
pub use password::Password;
extern crate hex;
extern crate unicode_normalization;
extern crate utils_results;
extern crate vep;
extern crate zeroize;
#[cfg(test)]
mod tests {
use super::*;
extern crate sha2;
use self::sha2::Sha256;
#[test]
fn validator() {
assert!("1234".parse::<Password<Sha256, 6>>().is_err());
assert!("123456".parse::<Password<Sha256, 6>>().is_ok());
assert!("이도하".parse::<Password<Sha256, 10>>().is_err());
assert!("이도하".parse::<Password<Sha256, 9>>().is_ok());
}
#[test]
fn encode_decode() {
let password: Password<Sha256, 8> = "12345678".parse().unwrap();
let bytes = password.to_bytes();
assert_eq!(password.as_slice(), bytes.as_slice());
let new_password = Password::<Sha256, 8>::from_bytes(bytes).unwrap();
assert_eq!(password, new_password);
let hex_string = password.to_hex().unwrap();
let new_password = Password::<Sha256, 8>::from_hex(hex_string).unwrap();
assert_eq!(password, new_password);
}
#[test]
fn parser() {
let password: Password<Sha256, 8> = "12345678".parse().unwrap();
let target = Password::<Sha256, 8>::new("12345678".to_string()).unwrap();
assert_eq!(password, target);
}
#[test]
fn equals() {
let password1 = Password::<Sha256, 3>::new("1234".to_string()).unwrap();
let password2: Password<Sha256, 3> = "1234".parse().unwrap();
assert_eq!(password1, password2);
assert_eq!(password1.as_ref(), password2.as_slice());
assert_eq!(password1.to_vec(), password2.to_vec());
assert_eq!(password1, "1234");
assert_eq!(password1, String::from("1234"));
}
#[test]
fn display() {
let pass1 = Password::<Sha256, 3>::new("1234".to_string()).unwrap();
let pass2 = Password::<Sha256, 3>::new("56789".to_string()).unwrap();
assert_eq!(String::from("***SECURE***"), format!("{}", pass1));
assert_eq!(format!("{}", pass1), format!("{}", pass2));
assert!(pass1 != pass2);
}
#[test]
fn normalizer() {
let password = Password::<Sha256, 5>::new(
"aliéneèbre, ácido, 쀏깕깕, ガバヴァぱばぐ, 十人十色".to_string(),
)
.unwrap();
assert_eq!(
password,
"aliéneèbre, ácido, 쀏깕깕, ガバヴァぱばぐ, 十人十色"
);
}
#[test]
fn nested() {
let first = Password::<Sha256, 5>::new("testman".to_string()).unwrap();
assert_eq!(32, first.len());
let second = Password::<Sha256, 5>::new(first.to_hex().unwrap()).unwrap();
assert_eq!(32, second.len());
}
}