diff --git a/src/cli.rs b/src/cli.rs index 4bae469..1b5d208 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -87,9 +87,9 @@ pub fn extend_creds_device( } pub fn read_password_pin_prefixed( - reader: impl Fn() -> Fido2LuksResult, + prefixed: impl Fn() -> Fido2LuksResult, ) -> Fido2LuksResult<(Option, [u8; 32])> { - let read = reader()?; + let read = prefixed()?; let separator = ':'; let mut parts = read.split(separator); let pin = parts.next().filter(|p| p.len() > 0).map(|p| p.to_string()); @@ -601,14 +601,17 @@ mod test { #[test] fn test_read_password_pin_prefixed() { + // 1234:test -> PIN: 1234, password: test assert_eq!( read_password_pin_prefixed(|| Ok("1234:test".into())).unwrap(), (Some("1234".to_string()), util::sha256(&["test".as_bytes()])) ); + // :test -> PIN: None, password: test assert_eq!( read_password_pin_prefixed(|| Ok(":test".into())).unwrap(), (None, util::sha256(&["test".as_bytes()])) ); + // 1234::test -> PIN: 1234, password: :test assert_eq!( read_password_pin_prefixed(|| Ok("1234::test".into())).unwrap(), ( @@ -616,10 +619,12 @@ mod test { util::sha256(&[":test".as_bytes()]) ) ); + // 1234 -> PIN: 1234, password: empty assert_eq!( read_password_pin_prefixed(|| Ok("1234".into())).unwrap(), (Some("1234".to_string()), util::sha256(&["".as_bytes()])) ); + // 1234:test -> PIN: None, password: test assert_eq!( read_password_pin_prefixed(|| Ok(":test".into())).unwrap(), (None, util::sha256(&["test".as_bytes()]))