diff --git a/card-functionality/src/tests.rs b/card-functionality/src/tests.rs index 8a6ea4a..2af2ef2 100644 --- a/card-functionality/src/tests.rs +++ b/card-functionality/src/tests.rs @@ -193,7 +193,7 @@ pub fn test_upload_keys( let cert = Cert::from_file(param[0])?; let p = StandardPolicy::new(); - let mut admin = tx.to_admin_card(b"12345678")?; + let mut admin = tx.to_admin_card("12345678")?; let meta = util::upload_subkeys(&mut admin, &cert, &p) .map_err(|e| TestError::KeyUploadError(param[0].to_string(), e))?; @@ -246,7 +246,7 @@ pub fn test_keygen(tx: &mut Card, param: &[&str]) -> Result, _param: &[&str]) -> Result { @@ -535,7 +535,7 @@ pub fn test_verify(mut card: Card, _param: &[&str]) -> Result { @@ -567,20 +567,20 @@ pub fn test_change_pw(mut card: Card, _param: &[&str]) -> Result { // this is expected } @@ -591,10 +591,10 @@ pub fn test_change_pw(mut card: Card, _param: &[&str]) -> Result { // this is expected } @@ -605,13 +605,13 @@ pub fn test_change_pw(mut card: Card, _param: &[&str]) -> Result { @@ -653,21 +653,21 @@ pub fn test_reset_retry_counter( } println!("verify pw3"); - transaction.verify_admin(b"12345678")?; + transaction.verify_admin("12345678")?; println!("set resetting code"); let mut admin = transaction.to_admin_card(None)?; - admin.set_resetting_code(b"abcdefgh")?; + admin.set_resetting_code("abcdefgh")?; println!("reset retry counter"); // ca.reset_retry_counter_pw1("abcdef".as_bytes().to_vec(), None)?; - let _res = transaction.reset_user_pin(b"abcdef", b"abcdefgh"); + let _res = transaction.reset_user_pin("abcdef", "abcdefgh"); println!("verify good pw1"); - transaction.verify_user(b"abcdef")?; + transaction.verify_user("abcdef")?; println!("verify bad pw1"); - match transaction.verify_user(b"00000000") { + match transaction.verify_user("00000000") { Err(Error::CardStatus(StatusBytes::SecurityStatusNotSatisfied)) => { // this is expected } diff --git a/openpgp-card-sequoia/examples/test.rs b/openpgp-card-sequoia/examples/test.rs index e208e83..19b8f7f 100644 --- a/openpgp-card-sequoia/examples/test.rs +++ b/openpgp-card-sequoia/examples/test.rs @@ -93,7 +93,7 @@ fn main() -> Result<(), Box> { println!("factory reset\n"); transaction.factory_reset()?; - transaction.verify_admin(b"12345678")?; + transaction.verify_admin("12345678")?; println!("verify for admin ok"); let check = transaction.check_user_verified(); @@ -152,7 +152,7 @@ fn main() -> Result<(), Box> { let check = transaction.check_user_verified(); println!("has user (pw1/82) been verified yet?\n{check:x?}\n"); - transaction.verify_user(b"123456")?; + transaction.verify_user("123456")?; println!("verify for user (pw1/82) ok"); let check = transaction.check_user_verified(); @@ -187,7 +187,7 @@ fn main() -> Result<(), Box> { let mut transaction = card.transaction()?; // Sign - transaction.verify_user_for_signing(b"123456")?; + transaction.verify_user_for_signing("123456")?; println!("verify for sign (pw1/81) ok\n"); // Use Sign access to card diff --git a/openpgp-card-sequoia/src/lib.rs b/openpgp-card-sequoia/src/lib.rs index 57da32f..142e3bf 100644 --- a/openpgp-card-sequoia/src/lib.rs +++ b/openpgp-card-sequoia/src/lib.rs @@ -312,8 +312,8 @@ impl<'a> Card> { } /// Verify the User PIN (for operations such as decryption) - pub fn verify_user(&mut self, pin: &[u8]) -> Result<(), Error> { - self.state.opt.verify_pw1_user(pin)?; + pub fn verify_user(&mut self, pin: &str) -> Result<(), Error> { + self.state.opt.verify_pw1_user(pin.as_bytes())?; self.state.pw1 = true; Ok(()) } @@ -333,8 +333,8 @@ impl<'a> Card> { /// (Note that depending on the configuration of the card, this may enable /// performing just one signing operation, or an unlimited amount of /// signing operations). - pub fn verify_user_for_signing(&mut self, pin: &[u8]) -> Result<(), Error> { - self.state.opt.verify_pw1_sign(pin)?; + pub fn verify_user_for_signing(&mut self, pin: &str) -> Result<(), Error> { + self.state.opt.verify_pw1_sign(pin.as_bytes())?; // FIXME: depending on card mode, pw1_sign is only usable once @@ -359,8 +359,8 @@ impl<'a> Card> { } /// Verify the Admin PIN. - pub fn verify_admin(&mut self, pin: &[u8]) -> Result<(), Error> { - self.state.opt.verify_pw3(pin)?; + pub fn verify_admin(&mut self, pin: &str) -> Result<(), Error> { + self.state.opt.verify_pw3(pin.as_bytes())?; self.state.pw3 = true; Ok(()) } @@ -392,8 +392,8 @@ impl<'a> Card> { } /// Change the User PIN, based on the old User PIN. - pub fn change_user_pin(&mut self, old: &[u8], new: &[u8]) -> Result<(), Error> { - self.state.opt.change_pw1(old, new) + pub fn change_user_pin(&mut self, old: &str, new: &str) -> Result<(), Error> { + self.state.opt.change_pw1(old.as_bytes(), new.as_bytes()) } /// Change the User PIN, based on the old User PIN, with a physical PIN @@ -404,13 +404,15 @@ impl<'a> Card> { } /// Change the User PIN, based on the resetting code `rst`. - pub fn reset_user_pin(&mut self, rst: &[u8], new: &[u8]) -> Result<(), Error> { - self.state.opt.reset_retry_counter_pw1(new, Some(rst)) + pub fn reset_user_pin(&mut self, rst: &str, new: &str) -> Result<(), Error> { + self.state + .opt + .reset_retry_counter_pw1(new.as_bytes(), Some(rst.as_bytes())) } /// Change the Admin PIN, based on the old Admin PIN. - pub fn change_admin_pin(&mut self, old: &[u8], new: &[u8]) -> Result<(), Error> { - self.state.opt.change_pw3(old, new) + pub fn change_admin_pin(&mut self, old: &str, new: &str) -> Result<(), Error> { + self.state.opt.change_pw3(old.as_bytes(), new.as_bytes()) } /// Change the Admin PIN, based on the old Admin PIN, with a physical PIN @@ -431,7 +433,7 @@ impl<'a> Card> { let pin: OptionalPin = pin.into(); if let Some(pin) = pin.0 { - self.verify_user(pin)?; + self.verify_user(String::from_utf8_lossy(pin).as_ref())?; } Ok(Card:: { @@ -450,7 +452,7 @@ impl<'a> Card> { let pin: OptionalPin = pin.into(); if let Some(pin) = pin.0 { - self.verify_user_for_signing(pin)?; + self.verify_user_for_signing(String::from_utf8_lossy(pin).as_ref())?; } Ok(Card:: { @@ -469,7 +471,7 @@ impl<'a> Card> { let pin: OptionalPin = pin.into(); if let Some(pin) = pin.0 { - self.verify_admin(pin)?; + self.verify_admin(String::from_utf8_lossy(pin).as_ref())?; } Ok(Card:: { @@ -1137,16 +1139,16 @@ impl Card> { Ok(()) } - pub fn set_resetting_code(&mut self, pin: &[u8]) -> Result<(), Error> { - self.card().set_resetting_code(pin) + pub fn set_resetting_code(&mut self, pin: &str) -> Result<(), Error> { + self.card().set_resetting_code(pin.as_bytes()) } pub fn set_pso_enc_dec_key(&mut self, key: &[u8]) -> Result<(), Error> { self.card().set_pso_enc_dec_key(key) } - pub fn reset_user_pin(&mut self, new: &[u8]) -> Result<(), Error> { - self.card().reset_retry_counter_pw1(new, None) + pub fn reset_user_pin(&mut self, new: &str) -> Result<(), Error> { + self.card().reset_retry_counter_pw1(new.as_bytes(), None) } /// Upload a ValidErasedKeyAmalgamation to the card as a specific KeyType. diff --git a/openpgp-card-sequoia/src/util.rs b/openpgp-card-sequoia/src/util.rs index 0288efe..91ec37b 100644 --- a/openpgp-card-sequoia/src/util.rs +++ b/openpgp-card-sequoia/src/util.rs @@ -42,7 +42,7 @@ pub fn make_cert( key_sig: PublicKey, key_dec: Option, key_aut: Option, - pw1: Option<&[u8]>, + pw1: Option<&str>, pinpad_prompt: &dyn Fn(), touch_prompt: &(dyn Fn() + Send + Sync), user_ids: &[String],