diff --git a/card-functionality/src/tests.rs b/card-functionality/src/tests.rs index 3cac087..68115f6 100644 --- a/card-functionality/src/tests.rs +++ b/card-functionality/src/tests.rs @@ -371,13 +371,13 @@ pub fn test_private_data( ca.verify_pw1("123456")?; - ca.set_private(1, "Foo bar1!".as_bytes().to_vec())?; - ca.set_private(3, "Foo bar3!".as_bytes().to_vec())?; + ca.set_private_use_do(1, "Foo bar1!".as_bytes().to_vec())?; + ca.set_private_use_do(3, "Foo bar3!".as_bytes().to_vec())?; ca.verify_pw3("12345678")?; - ca.set_private(2, "Foo bar2!".as_bytes().to_vec())?; - ca.set_private(4, "Foo bar4!".as_bytes().to_vec())?; + ca.set_private_use_do(2, "Foo bar2!".as_bytes().to_vec())?; + ca.set_private_use_do(4, "Foo bar4!".as_bytes().to_vec())?; let d = ca.private_use_do(1)?; println!("data 1 {:?}", d); diff --git a/openpgp-card/src/apdu/commands.rs b/openpgp-card/src/apdu/commands.rs index de27113..d67400d 100644 --- a/openpgp-card/src/apdu/commands.rs +++ b/openpgp-card/src/apdu/commands.rs @@ -37,7 +37,7 @@ pub(crate) fn application_related_data() -> Command { } /// GET DO "private use" -pub(crate) fn private_do(num: u8) -> Command { +pub(crate) fn private_use_do(num: u8) -> Command { get_data(&[0x01, num]) } @@ -115,7 +115,7 @@ pub(crate) fn put_data(tag: &[u8], data: Vec) -> Command { } /// PUT DO "private use" -pub(crate) fn put_private_do(num: u8, data: Vec) -> Command { +pub(crate) fn put_private_use_do(num: u8, data: Vec) -> Command { put_data(&[0x01, num], data) } diff --git a/openpgp-card/src/card_app.rs b/openpgp-card/src/card_app.rs index e44ce2d..8e8638b 100644 --- a/openpgp-card/src/card_app.rs +++ b/openpgp-card/src/card_app.rs @@ -131,18 +131,6 @@ impl CardApp { Ok(ApplicationRelatedData(Tlv::new(Tag::from([0x6E]), value))) } - /// Get data from "private use" DO. - /// - /// `num` must be between 1 and 4. - pub fn private_use_do(&mut self, num: u8) -> Result> { - assert!((1..=4).contains(&num)); - - let cmd = commands::private_do(num); - let resp = apdu::send_command(self.card_client(), cmd, true)?; - - Ok(resp.data()?.to_vec()) - } - #[allow(dead_code)] fn ca_fingerprints() { unimplemented!() @@ -173,8 +161,6 @@ impl CardApp { unimplemented!() } - // --- optional private DOs (0101 - 0104) --- - // --- login data (5e) --- /// Get URL (5f50) @@ -294,6 +280,40 @@ impl CardApp { apdu::send_command(self.card_client(), cmd, true)?.try_into() } + // --- optional private DOs (0101 - 0104) --- + + /// Get data from "private use" DO. + /// + /// `num` must be between 1 and 4. + pub fn private_use_do(&mut self, num: u8) -> Result> { + assert!((1..=4).contains(&num)); + + let cmd = commands::private_use_do(num); + let resp = apdu::send_command(self.card_client(), cmd, true)?; + + Ok(resp.data()?.to_vec()) + } + + /// Set data of "private use" DO. + /// + /// `num` must be between 1 and 4. + /// + /// Access condition: + /// - 1/3 need PW1 (82) + /// - 2/4 need PW3 + pub fn set_private_use_do( + &mut self, + num: u8, + data: Vec, + ) -> Result> { + assert!((1..=4).contains(&num)); + + let cmd = commands::put_private_use_do(num, data); + let resp = apdu::send_command(self.card_client(), cmd, true)?; + + Ok(resp.data()?.to_vec()) + } + // ---------- /// Reset all state on this OpenPGP card. @@ -658,22 +678,6 @@ impl CardApp { // --- admin --- - /// Set data of "private use" DO. - /// - /// `num` must be between 1 and 4. - /// - /// Access condition: - /// - 1/3 need PW1 (82) - /// - 2/4 need PW3 - pub fn set_private(&mut self, num: u8, data: Vec) -> Result> { - assert!((1..=4).contains(&num)); - - let cmd = commands::put_private_do(num, data); - let resp = apdu::send_command(self.card_client(), cmd, true)?; - - Ok(resp.data()?.to_vec()) - } - pub fn set_name(&mut self, name: &str) -> Result { let put_name = commands::put_name(name.as_bytes().to_vec()); apdu::send_command(self.card_client(), put_name, false)?.try_into()