diff --git a/openpgp-card-sequoia/src/card.rs b/openpgp-card-sequoia/src/card.rs index c599966..ea9fd1a 100644 --- a/openpgp-card-sequoia/src/card.rs +++ b/openpgp-card-sequoia/src/card.rs @@ -6,6 +6,8 @@ use anyhow::{anyhow, Result}; +use sequoia_openpgp::cert::amalgamation::key::ValidErasedKeyAmalgamation; +use sequoia_openpgp::packet::key::SecretParts; use sequoia_openpgp::policy::Policy; use sequoia_openpgp::Cert; @@ -21,6 +23,7 @@ use openpgp_card::{CardApp, CardClientBox, Error, KeySet, KeyType, Response}; use crate::decryptor::CardDecryptor; use crate::signer::CardSigner; +use crate::util::vka_as_uploadable_key; /// Representation of an opened OpenPGP card in its base state (i.e. no /// passwords have been verified, default authorization applies). @@ -340,11 +343,16 @@ impl Admin<'_> { } } + /// Upload a ValidErasedKeyAmalgamation to the card as a specific KeyType. + /// + /// (The caller needs to make sure that `vka` is suitable as `key_type`) pub fn upload_key( &mut self, - key: Box, + vka: ValidErasedKeyAmalgamation, key_type: KeyType, + password: Option, ) -> Result<(), Error> { + let key = vka_as_uploadable_key(vka, password); self.oc.card_app.key_import(key, key_type) } } diff --git a/openpgp-card-sequoia/src/main.rs b/openpgp-card-sequoia/src/main.rs index 60152be..840f5cd 100644 --- a/openpgp-card-sequoia/src/main.rs +++ b/openpgp-card-sequoia/src/main.rs @@ -15,7 +15,6 @@ use openpgp_card_pcsc::PcscClient; use openpgp_card_sequoia::card::Open; use openpgp_card_sequoia::sq_util::{decryption_helper, sign_helper}; -use openpgp_card_sequoia::util::upload_key; // Filename of test key and test message to use @@ -124,7 +123,7 @@ fn main() -> Result<(), Box> { &p, KeyType::Decryption, )?; - upload_key(&mut admin, vka, KeyType::Decryption, None)?; + admin.upload_key(vka, KeyType::Decryption, None)?; println!("Upload signing key"); let vka = openpgp_card_sequoia::sq_util::get_subkey( @@ -132,7 +131,7 @@ fn main() -> Result<(), Box> { &p, KeyType::Signing, )?; - upload_key(&mut admin, vka, KeyType::Signing, None)?; + admin.upload_key(vka, KeyType::Signing, None)?; println!("Upload auth key"); let vka = openpgp_card_sequoia::sq_util::get_subkey( @@ -140,7 +139,7 @@ fn main() -> Result<(), Box> { &p, KeyType::Authentication, )?; - upload_key(&mut admin, vka, KeyType::Authentication, None)?; + admin.upload_key(vka, KeyType::Authentication, None)?; println!(); diff --git a/openpgp-card-sequoia/src/util.rs b/openpgp-card-sequoia/src/util.rs index e618c06..25349f5 100644 --- a/openpgp-card-sequoia/src/util.rs +++ b/openpgp-card-sequoia/src/util.rs @@ -147,15 +147,6 @@ pub fn make_cert( Cert::try_from(pp) } -/// Helper fn: get a CardUploadableKey for a ValidErasedKeyAmalgamation -pub fn vka_as_uploadable_key( - vka: ValidErasedKeyAmalgamation, - password: Option, -) -> Box { - let sqk = SequoiaKey::new(vka, password); - Box::new(sqk) -} - /// Helper fn: get a Sequoia PublicKey from an openpgp-card PublicKeyMaterial pub fn public_key_material_to_key( pkm: &PublicKeyMaterial, @@ -259,18 +250,13 @@ pub fn public_to_fingerprint( fp.as_bytes().try_into() } -/// Upload a ValidErasedKeyAmalgamation to the card as a specific KeyType. -/// -/// The caller needs to make sure that `vka` is suitable for `key_type`. -pub fn upload_key( - oca: &mut Admin, +/// Helper fn: get a CardUploadableKey for a ValidErasedKeyAmalgamation +pub fn vka_as_uploadable_key( vka: ValidErasedKeyAmalgamation, - key_type: KeyType, password: Option, -) -> Result<(), Error> { +) -> Box { let sqk = SequoiaKey::new(vka, password); - - oca.upload_key(Box::new(sqk), key_type) + Box::new(sqk) } /// FIXME: this fn is used in card_functionality, but should be removed