Normalize naming of "private use" DO related fn.

This commit is contained in:
Heiko Schaefer 2021-12-02 18:00:51 +01:00
parent 133b290ae6
commit 281bf403e3
No known key found for this signature in database
GPG key ID: 4A849A1904CCBD7D
3 changed files with 40 additions and 36 deletions

View file

@ -371,13 +371,13 @@ pub fn test_private_data(
ca.verify_pw1("123456")?; ca.verify_pw1("123456")?;
ca.set_private(1, "Foo bar1!".as_bytes().to_vec())?; ca.set_private_use_do(1, "Foo bar1!".as_bytes().to_vec())?;
ca.set_private(3, "Foo bar3!".as_bytes().to_vec())?; ca.set_private_use_do(3, "Foo bar3!".as_bytes().to_vec())?;
ca.verify_pw3("12345678")?; ca.verify_pw3("12345678")?;
ca.set_private(2, "Foo bar2!".as_bytes().to_vec())?; ca.set_private_use_do(2, "Foo bar2!".as_bytes().to_vec())?;
ca.set_private(4, "Foo bar4!".as_bytes().to_vec())?; ca.set_private_use_do(4, "Foo bar4!".as_bytes().to_vec())?;
let d = ca.private_use_do(1)?; let d = ca.private_use_do(1)?;
println!("data 1 {:?}", d); println!("data 1 {:?}", d);

View file

@ -37,7 +37,7 @@ pub(crate) fn application_related_data() -> Command {
} }
/// GET DO "private use" /// 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]) get_data(&[0x01, num])
} }
@ -115,7 +115,7 @@ pub(crate) fn put_data(tag: &[u8], data: Vec<u8>) -> Command {
} }
/// PUT DO "private use" /// PUT DO "private use"
pub(crate) fn put_private_do(num: u8, data: Vec<u8>) -> Command { pub(crate) fn put_private_use_do(num: u8, data: Vec<u8>) -> Command {
put_data(&[0x01, num], data) put_data(&[0x01, num], data)
} }

View file

@ -131,18 +131,6 @@ impl CardApp {
Ok(ApplicationRelatedData(Tlv::new(Tag::from([0x6E]), value))) 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<Vec<u8>> {
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)] #[allow(dead_code)]
fn ca_fingerprints() { fn ca_fingerprints() {
unimplemented!() unimplemented!()
@ -173,8 +161,6 @@ impl CardApp {
unimplemented!() unimplemented!()
} }
// --- optional private DOs (0101 - 0104) ---
// --- login data (5e) --- // --- login data (5e) ---
/// Get URL (5f50) /// Get URL (5f50)
@ -294,6 +280,40 @@ impl CardApp {
apdu::send_command(self.card_client(), cmd, true)?.try_into() 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<Vec<u8>> {
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<u8>,
) -> Result<Vec<u8>> {
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. /// Reset all state on this OpenPGP card.
@ -658,22 +678,6 @@ impl CardApp {
// --- admin --- // --- 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<u8>) -> Result<Vec<u8>> {
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<Response, Error> { pub fn set_name(&mut self, name: &str) -> Result<Response, Error> {
let put_name = commands::put_name(name.as_bytes().to_vec()); let put_name = commands::put_name(name.as_bytes().to_vec());
apdu::send_command(self.card_client(), put_name, false)?.try_into() apdu::send_command(self.card_client(), put_name, false)?.try_into()