Rename Open::open() to Open::new()

This commit is contained in:
Heiko Schaefer 2021-11-11 16:37:23 +01:00
parent d10cbe8eff
commit 7a71f88eb6
No known key found for this signature in database
GPG key ID: 4A849A1904CCBD7D
9 changed files with 23 additions and 27 deletions

View file

@ -10,7 +10,7 @@ fn main() -> Result<()> {
println!("The following OpenPGP cards are connected to your system:"); println!("The following OpenPGP cards are connected to your system:");
for mut ca in PcscClient::cards()? { for mut ca in PcscClient::cards()? {
let open = Open::open(&mut ca)?; let open = Open::new(&mut ca)?;
println!(" {}", open.application_identifier()?.ident()); println!(" {}", open.application_identifier()?.ident());
} }

View file

@ -254,7 +254,7 @@ pub fn test_keygen(
public_key_material_to_key(&pkm, KeyType::Authentication, ts)?; public_key_material_to_key(&pkm, KeyType::Authentication, ts)?;
// Generate a Cert for this set of generated keys // Generate a Cert for this set of generated keys
let mut open = Open::open(&mut ca)?; let mut open = Open::new(&mut ca)?;
let cert = let cert =
make_cert(&mut open, key_sig, Some(key_dec), Some(key_aut), "123456")?; make_cert(&mut open, key_sig, Some(key_dec), Some(key_aut), "123456")?;
let armored = String::from_utf8(cert.armored().to_vec()?)?; let armored = String::from_utf8(cert.armored().to_vec()?)?;

View file

@ -23,7 +23,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let cert_file = &args[2]; let cert_file = &args[2];
let mut ca = PcscClient::open_by_ident(card_ident)?; let mut ca = PcscClient::open_by_ident(card_ident)?;
let mut open = Open::open(&mut ca)?; let mut open = Open::new(&mut ca)?;
let pin = std::fs::read_to_string(pin_file)?; let pin = std::fs::read_to_string(pin_file)?;

View file

@ -24,7 +24,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let cert_file = &args[2]; let cert_file = &args[2];
let mut ca = PcscClient::open_by_ident(card_ident)?; let mut ca = PcscClient::open_by_ident(card_ident)?;
let mut open = Open::open(&mut ca)?; let mut open = Open::new(&mut ca)?;
let pin = std::fs::read_to_string(pin_file)?; let pin = std::fs::read_to_string(pin_file)?;

View file

@ -47,22 +47,18 @@ pub struct Open<'a> {
} }
impl<'a> Open<'a> { impl<'a> Open<'a> {
pub fn open(card_app: &'a mut CardApp) -> Result<Self, Error> { pub fn new(card_app: &'a mut CardApp) -> Result<Self, Error> {
let ard = card_app.get_application_related_data()?; let ard = card_app.get_application_related_data()?;
card_app.init_caps(&ard)?; card_app.init_caps(&ard)?;
Ok(Self::new(card_app, ard)) Ok(Self {
}
fn new(card_app: &'a mut CardApp, ard: ApplicationRelatedData) -> Self {
Self {
card_app, card_app,
ard, ard,
pw1: false, pw1: false,
pw1_sign: false, pw1_sign: false,
pw3: false, pw3: false,
} })
} }
pub fn verify_user(&mut self, pin: &str) -> Result<(), Error> { pub fn verify_user(&mut self, pin: &str) -> Result<(), Error> {

View file

@ -18,7 +18,7 @@
//! # fn main() -> Result<(), Box<dyn std::error::Error>> { //! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! for card in PcscClient::cards()? { //! for card in PcscClient::cards()? {
//! let mut ca = card.into(); //! let mut ca = card.into();
//! let open = Open::open(&mut ca)?; //! let open = Open::new(&mut ca)?;
//! println!("Found OpenPGP card with ident '{}'", //! println!("Found OpenPGP card with ident '{}'",
//! open.application_identifier()?.ident()); //! open.application_identifier()?.ident());
//! } //! }
@ -34,7 +34,7 @@
//! //!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> { //! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut ca = PcscClient::open_by_ident("abcd:12345678")?.into(); //! let mut ca = PcscClient::open_by_ident("abcd:12345678")?.into();
//! let mut open = Open::open(&mut ca)?; //! let mut open = Open::new(&mut ca)?;
//! # Ok(()) //! # Ok(())
//! # } //! # }
//! ``` //! ```
@ -56,7 +56,7 @@
//! // Open card via PCSC //! // Open card via PCSC
//! use sequoia_openpgp::policy::StandardPolicy; //! use sequoia_openpgp::policy::StandardPolicy;
//! let mut ca = PcscClient::open_by_ident("abcd:12345678")?.into(); //! let mut ca = PcscClient::open_by_ident("abcd:12345678")?.into();
//! let mut open = Open::open(&mut ca)?; //! let mut open = Open::new(&mut ca)?;
//! //!
//! // Get authorization for user access to the card with password //! // Get authorization for user access to the card with password
//! open.verify_user("123456")?; //! open.verify_user("123456")?;
@ -97,7 +97,7 @@
//! // Open card via PCSC //! // Open card via PCSC
//! use sequoia_openpgp::policy::StandardPolicy; //! use sequoia_openpgp::policy::StandardPolicy;
//! let mut ca = PcscClient::open_by_ident("abcd:12345678")?.into(); //! let mut ca = PcscClient::open_by_ident("abcd:12345678")?.into();
//! let mut open = Open::open(&mut ca)?; //! let mut open = Open::new(&mut ca)?;
//! //!
//! // Get authorization for signing access to the card with password //! // Get authorization for signing access to the card with password
//! open.verify_user_for_signing("123456")?; //! open.verify_user_for_signing("123456")?;
@ -127,7 +127,7 @@
//! # fn main() -> Result<(), Box<dyn std::error::Error>> { //! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Open card via PCSC //! // Open card via PCSC
//! let mut ca = PcscClient::open_by_ident("abcd:12345678")?.into(); //! let mut ca = PcscClient::open_by_ident("abcd:12345678")?.into();
//! let mut open = Open::open(&mut ca)?; //! let mut open = Open::new(&mut ca)?;
//! //!
//! // Get authorization for admin access to the card with password //! // Get authorization for admin access to the card with password
//! open.verify_admin("12345678")?; //! open.verify_admin("12345678")?;

View file

@ -36,7 +36,7 @@ fn main() -> Result<(), Box<dyn Error>> {
if let Ok(test_card_ident) = test_card_ident { if let Ok(test_card_ident) = test_card_ident {
let mut card = PcscClient::open_by_ident(&test_card_ident)?; let mut card = PcscClient::open_by_ident(&test_card_ident)?;
let mut open = Open::open(&mut card)?; let mut open = Open::new(&mut card)?;
// card metadata // card metadata
@ -151,7 +151,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// Open fresh Card for decrypt // Open fresh Card for decrypt
// ----------------------------- // -----------------------------
let mut card = PcscClient::open_by_ident(&test_card_ident)?; let mut card = PcscClient::open_by_ident(&test_card_ident)?;
let mut open = Open::open(&mut card)?; let mut open = Open::new(&mut card)?;
// Check that we're still using the expected card // Check that we're still using the expected card
let app_id = open.application_identifier()?; let app_id = open.application_identifier()?;
@ -190,7 +190,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// Open fresh Card for signing // Open fresh Card for signing
// ----------------------------- // -----------------------------
let mut card = PcscClient::open_by_ident(&test_card_ident)?; let mut card = PcscClient::open_by_ident(&test_card_ident)?;
let mut open = Open::open(&mut card)?; let mut open = Open::new(&mut card)?;
// Sign // Sign
open.verify_user_for_signing("123456")?; open.verify_user_for_signing("123456")?;
@ -220,7 +220,7 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("The following OpenPGP cards are connected to your system:"); println!("The following OpenPGP cards are connected to your system:");
for mut card in PcscClient::cards()? { for mut card in PcscClient::cards()? {
let open = Open::open(&mut card)?; let open = Open::new(&mut card)?;
println!(" {}", open.application_identifier()?.ident()); println!(" {}", open.application_identifier()?.ident());
} }
} }

View file

@ -14,7 +14,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let cli = cli::Cli::from_args(); let cli = cli::Cli::from_args();
let mut card = PcscClient::open_by_ident(&cli.ident)?; let mut card = PcscClient::open_by_ident(&cli.ident)?;
let mut open = Open::open(&mut card)?; let mut open = Open::new(&mut card)?;
match cli.cmd { match cli.cmd {
cli::Command::SetUserPin {} => { cli::Command::SetUserPin {} => {

View file

@ -72,7 +72,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
cmd, cmd,
} => { } => {
let mut card = util::open_card(&ident)?; let mut card = util::open_card(&ident)?;
let mut open = Open::open(&mut card)?; let mut open = Open::new(&mut card)?;
match cmd { match cmd {
cli::AdminCommand::Name { name } => { cli::AdminCommand::Name { name } => {
@ -138,7 +138,7 @@ fn list_cards() -> Result<()> {
println!("Available OpenPGP cards:"); println!("Available OpenPGP cards:");
for mut card in cards { for mut card in cards {
let open = Open::open(&mut card)?; let open = Open::new(&mut card)?;
println!(" {}", open.application_identifier()?.ident()); println!(" {}", open.application_identifier()?.ident());
} }
} else { } else {
@ -158,7 +158,7 @@ fn print_status(ident: Option<String>, verbose: bool) -> Result<()> {
return Err(anyhow::anyhow!("Found {} cards", cards.len())); return Err(anyhow::anyhow!("Found {} cards", cards.len()));
} }
}; };
let mut open = Open::open(&mut ca)?; let mut open = Open::new(&mut ca)?;
print!("OpenPGP card {}", open.application_identifier()?.ident()); print!("OpenPGP card {}", open.application_identifier()?.ident());
@ -290,7 +290,7 @@ fn decrypt(
let input = util::open_or_stdin(input.as_deref())?; let input = util::open_or_stdin(input.as_deref())?;
let mut card = util::open_card(ident)?; let mut card = util::open_card(ident)?;
let mut open = Open::open(&mut card)?; let mut open = Open::new(&mut card)?;
let mut user = util::get_user(&mut open, pin_file)?; let mut user = util::get_user(&mut open, pin_file)?;
let d = user.decryptor(&cert, &p)?; let d = user.decryptor(&cert, &p)?;
@ -315,7 +315,7 @@ fn sign_detached(
let mut input = util::open_or_stdin(input.as_deref())?; let mut input = util::open_or_stdin(input.as_deref())?;
let mut card = util::open_card(ident)?; let mut card = util::open_card(ident)?;
let mut open = Open::open(&mut card)?; let mut open = Open::new(&mut card)?;
let mut sign = util::get_sign(&mut open, pin_file)?; let mut sign = util::get_sign(&mut open, pin_file)?;
let s = sign.signer(&cert, &p)?; let s = sign.signer(&cert, &p)?;
@ -332,7 +332,7 @@ fn sign_detached(
fn factory_reset(ident: &str) -> Result<()> { fn factory_reset(ident: &str) -> Result<()> {
println!("Resetting Card {}", ident); println!("Resetting Card {}", ident);
let mut card = util::open_card(ident)?; let mut card = util::open_card(ident)?;
Open::open(&mut card)?.factory_reset() Open::new(&mut card)?.factory_reset()
} }
fn key_import_yolo(mut admin: Admin, key: &Cert) -> Result<()> { fn key_import_yolo(mut admin: Admin, key: &Cert) -> Result<()> {