Normalize fn names: remove 'get_' prefixes, and adjust to naming in the spec.

This commit is contained in:
Heiko Schaefer 2021-09-10 22:16:57 +02:00
parent 0e2b53feb4
commit be95b9de43
3 changed files with 51 additions and 45 deletions

View file

@ -13,7 +13,8 @@ use openpgp_card::algorithm::{Algo, AlgoInfo};
use openpgp_card::card_do::{ use openpgp_card::card_do::{
ApplicationIdentifier, ApplicationRelatedData, CardholderRelatedData, ApplicationIdentifier, ApplicationRelatedData, CardholderRelatedData,
ExCapFeatures, ExtendedCapabilities, ExtendedLengthInfo, Fingerprint, ExCapFeatures, ExtendedCapabilities, ExtendedLengthInfo, Fingerprint,
HistoricalBytes, PWStatusBytes, SecuritySupportTemplate, Sex, HistoricalBytes, KeyGenerationTime, PWStatusBytes,
SecuritySupportTemplate, Sex,
}; };
use openpgp_card::crypto_data::CardUploadableKey; use openpgp_card::crypto_data::CardUploadableKey;
use openpgp_card::{CardApp, CardClientBox, Error, KeySet, KeyType, Response}; use openpgp_card::{CardApp, CardClientBox, Error, KeySet, KeyType, Response};
@ -103,7 +104,7 @@ impl Open {
self.card_app.check_pw3() self.card_app.check_pw3()
} }
/// Get a view of the card authenticated for "User" commands. /// Get a view of the card authenticated for "User" commands.
pub fn get_user(&mut self) -> Option<User> { pub fn user_card(&mut self) -> Option<User> {
if self.pw1 { if self.pw1 {
Some(User { oc: self }) Some(User { oc: self })
} else { } else {
@ -112,7 +113,7 @@ impl Open {
} }
/// Get a view of the card authenticated for Signing. /// Get a view of the card authenticated for Signing.
pub fn get_sign(&mut self) -> Option<Sign> { pub fn signing_card(&mut self) -> Option<Sign> {
if self.pw1_sign { if self.pw1_sign {
Some(Sign { oc: self }) Some(Sign { oc: self })
} else { } else {
@ -121,7 +122,7 @@ impl Open {
} }
/// Get a view of the card authenticated for "Admin" commands. /// Get a view of the card authenticated for "Admin" commands.
pub fn get_admin(&mut self) -> Option<Admin> { pub fn admin_card(&mut self) -> Option<Admin> {
if self.pw3 { if self.pw3 {
Some(Admin { oc: self }) Some(Admin { oc: self })
} else { } else {
@ -135,75 +136,80 @@ impl Open {
/// ///
/// This is done once, after opening the OpenPGP card applet /// This is done once, after opening the OpenPGP card applet
/// (the data is stored in the OpenPGPCard object). /// (the data is stored in the OpenPGPCard object).
fn get_app_data(&mut self) -> Result<ApplicationRelatedData> { fn application_related_data(&mut self) -> Result<ApplicationRelatedData> {
self.card_app.get_application_related_data() self.card_app.get_application_related_data()
} }
pub fn get_application_id(&self) -> Result<ApplicationIdentifier, Error> { pub fn application_identifier(
&self,
) -> Result<ApplicationIdentifier, Error> {
self.ard.get_application_id() self.ard.get_application_id()
} }
pub fn get_historical(&self) -> Result<HistoricalBytes, Error> { pub fn historical_bytes(&self) -> Result<HistoricalBytes, Error> {
self.ard.get_historical() self.ard.get_historical()
} }
pub fn get_extended_length_information( pub fn extended_length_information(
&self, &self,
) -> Result<Option<ExtendedLengthInfo>> { ) -> Result<Option<ExtendedLengthInfo>> {
self.ard.get_extended_length_information() self.ard.get_extended_length_information()
} }
pub fn get_general_feature_management() -> Option<bool> { fn general_feature_management() -> Option<bool> {
unimplemented!() unimplemented!()
} }
pub fn get_discretionary_data_objects() { fn discretionary_data_objects() {
unimplemented!() unimplemented!()
} }
pub fn get_extended_capabilities( pub fn extended_capabilities(
&self, &self,
) -> Result<ExtendedCapabilities, Error> { ) -> Result<ExtendedCapabilities, Error> {
self.ard.get_extended_capabilities() self.ard.get_extended_capabilities()
} }
pub fn get_algorithm_attributes(&self, key_type: KeyType) -> Result<Algo> { pub fn algorithm_attributes(&self, key_type: KeyType) -> Result<Algo> {
self.ard.get_algorithm_attributes(key_type) self.ard.get_algorithm_attributes(key_type)
} }
/// PW status Bytes /// PW status Bytes
pub fn get_pw_status_bytes(&self) -> Result<PWStatusBytes> { pub fn pw_status_bytes(&self) -> Result<PWStatusBytes> {
self.ard.get_pw_status_bytes() self.ard.get_pw_status_bytes()
} }
pub fn get_fingerprints(&self) -> Result<KeySet<Fingerprint>, Error> { pub fn fingerprints(&self) -> Result<KeySet<Fingerprint>, Error> {
self.ard.get_fingerprints() self.ard.get_fingerprints()
} }
pub fn get_ca_fingerprints(&self) { fn ca_fingerprints(&self) {
unimplemented!() unimplemented!()
} }
pub fn get_key_generation_times() { pub fn key_generation_times(
&self,
) -> Result<KeySet<KeyGenerationTime>, Error> {
self.ard.get_key_generation_times()
}
fn key_information() {
unimplemented!() unimplemented!()
} }
pub fn get_key_information() { fn uif_pso_cds() {
unimplemented!() unimplemented!()
} }
pub fn get_uif_pso_cds() { fn uif_pso_dec() {
unimplemented!() unimplemented!()
} }
pub fn get_uif_pso_dec() { fn uif_pso_aut() {
unimplemented!() unimplemented!()
} }
pub fn get_uif_pso_aut() { fn uif_attestation() {
unimplemented!()
}
pub fn get_uif_attestation() {
unimplemented!() unimplemented!()
} }
@ -213,29 +219,29 @@ impl Open {
// --- URL (5f50) --- // --- URL (5f50) ---
pub fn get_url(&mut self) -> Result<String> { pub fn url(&mut self) -> Result<String> {
self.card_app.get_url() self.card_app.get_url()
} }
// --- cardholder related data (65) --- // --- cardholder related data (65) ---
pub fn get_cardholder_related_data( pub fn cardholder_related_data(
&mut self, &mut self,
) -> Result<CardholderRelatedData> { ) -> Result<CardholderRelatedData> {
self.card_app.get_cardholder_related_data() self.card_app.get_cardholder_related_data()
} }
// --- security support template (7a) --- // --- security support template (7a) ---
pub fn get_security_support_template( pub fn security_support_template(
&mut self, &mut self,
) -> Result<SecuritySupportTemplate> { ) -> Result<SecuritySupportTemplate> {
self.card_app.get_security_support_template() self.card_app.get_security_support_template()
} }
// DO "Algorithm Information" (0xFA) // DO "Algorithm Information" (0xFA)
pub fn list_supported_algo(&mut self) -> Result<Option<AlgoInfo>> { pub fn algorithm_information(&mut self) -> Result<Option<AlgoInfo>> {
// The DO "Algorithm Information" (Tag FA) shall be present if // The DO "Algorithm Information" (Tag FA) shall be present if
// Algorithm attributes can be changed // Algorithm attributes can be changed
let ec = self.get_extended_capabilities()?; let ec = self.extended_capabilities()?;
if !ec.features().contains(&ExCapFeatures::AlgoAttrsChangeable) { if !ec.features().contains(&ExCapFeatures::AlgoAttrsChangeable) {
// Algorithm attributes can not be changed, // Algorithm attributes can not be changed,
// list_supported_algo is not supported // list_supported_algo is not supported
@ -325,7 +331,7 @@ impl Admin<'_> {
} }
// Check for max len // Check for max len
let ec = self.oc.get_extended_capabilities()?; let ec = self.oc.extended_capabilities()?;
if url.len() < ec.max_len_special_do() as usize { if url.len() < ec.max_len_special_do() as usize {
self.oc.card_app.set_url(url) self.oc.card_app.set_url(url)

View file

@ -19,7 +19,7 @@
//! for card in PcscClient::cards()? { //! for card in PcscClient::cards()? {
//! let open = Open::open_card(card)?; //! let open = Open::open_card(card)?;
//! println!("Found OpenPGP card with ident '{}'", //! println!("Found OpenPGP card with ident '{}'",
//! open.get_application_id()?.ident()); //! open.application_identifier()?.ident());
//! } //! }
//! # Ok(()) //! # Ok(())
//! # } //! # }

View file

@ -51,47 +51,47 @@ fn main() -> Result<(), Box<dyn Error>> {
// card metadata // card metadata
println!("** get aid"); println!("** get aid");
let app_id = oc.get_application_id()?; let app_id = oc.application_identifier()?;
println!("app id: {:x?}", app_id); println!("app id: {:x?}", app_id);
println!(); println!();
let eli = oc.get_extended_length_information()?; let eli = oc.extended_length_information()?;
println!("extended_length_info: {:?}", eli); println!("extended_length_info: {:?}", eli);
println!(); println!();
let hist = oc.get_historical()?; let hist = oc.historical_bytes()?;
println!("{:#x?}", hist); println!("{:#x?}", hist);
println!(); println!();
let ext = oc.get_extended_capabilities()?; let ext = oc.extended_capabilities()?;
println!("{:#x?}", ext); println!("{:#x?}", ext);
println!(); println!();
let pws = oc.get_pw_status_bytes()?; let pws = oc.pw_status_bytes()?;
println!("{:#x?}", pws); println!("{:#x?}", pws);
println!(); println!();
// cardholder // cardholder
let ch = oc.get_cardholder_related_data()?; let ch = oc.cardholder_related_data()?;
println!("{:#x?}", ch); println!("{:#x?}", ch);
println!(); println!();
// crypto-ish metadata // crypto-ish metadata
let fp = oc.get_fingerprints()?; let fp = oc.fingerprints()?;
println!("Fingerprint {:#x?}", fp); println!("Fingerprint {:#x?}", fp);
println!(); println!();
match oc.list_supported_algo() { match oc.algorithm_information() {
Ok(Some(ai)) => println!("Algorithm information:\n{}", ai), Ok(Some(ai)) => println!("Algorithm information:\n{}", ai),
Ok(None) => println!("No Algorithm information found"), Ok(None) => println!("No Algorithm information found"),
Err(e) => println!("Error getting Algorithm information: {:?}", e), Err(e) => println!("Error getting Algorithm information: {:?}", e),
} }
let algo = oc.get_algorithm_attributes(KeyType::Signing)?; let algo = oc.algorithm_attributes(KeyType::Signing)?;
println!("Sig: {}", algo); println!("Sig: {}", algo);
let algo = oc.get_algorithm_attributes(KeyType::Decryption)?; let algo = oc.algorithm_attributes(KeyType::Decryption)?;
println!("Dec: {}", algo); println!("Dec: {}", algo);
let algo = oc.get_algorithm_attributes(KeyType::Authentication)?; let algo = oc.algorithm_attributes(KeyType::Authentication)?;
println!("Aut: {}", algo); println!("Aut: {}", algo);
println!(); println!();
@ -115,7 +115,7 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("has pw1/82 been verified yet? {:x?}", check); println!("has pw1/82 been verified yet? {:x?}", check);
// actually take Admin // actually take Admin
let mut oc_admin = oc.get_admin().expect("just verified"); let mut oc_admin = oc.admin_card().expect("just verified");
let res = oc_admin.set_name("Bar<<Foo")?; let res = oc_admin.set_name("Bar<<Foo")?;
println!("set name {:x?}", res); println!("set name {:x?}", res);
@ -168,7 +168,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// &test_card_serial, // &test_card_serial,
// )?)?; // )?)?;
let app_id = oc.get_application_id()?; let app_id = oc.application_identifier()?;
// Check that we're still using the expected card // Check that we're still using the expected card
assert_eq!(app_id.ident(), test_card_ident); assert_eq!(app_id.ident(), test_card_ident);
@ -183,7 +183,7 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("has pw1/82 been verified yet? {:x?}", check); println!("has pw1/82 been verified yet? {:x?}", check);
// actually take User // actually take User
let mut oc_user = oc.get_user().expect("just verified"); let mut oc_user = oc.user_card().expect("just verified");
let cert = Cert::from_file(TEST_KEY_PATH)?; let cert = Cert::from_file(TEST_KEY_PATH)?;
let msg = std::fs::read_to_string(TEST_ENC_MSG) let msg = std::fs::read_to_string(TEST_ENC_MSG)
@ -221,7 +221,7 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("pw1 81 verify ok"); println!("pw1 81 verify ok");
// actually take Sign // actually take Sign
let mut oc_sign = oc.get_sign().expect("just verified"); let mut oc_sign = oc.signing_card().expect("just verified");
let cert = Cert::from_file(TEST_KEY_PATH)?; let cert = Cert::from_file(TEST_KEY_PATH)?;