Add Card to the openpgp-card-sequoia API, as a wrapper around a CardBackend/OpenPgp.

This allows using the openpgp-card-sequoia API without needing the crate openpgp-card.
This commit is contained in:
Heiko Schaefer 2022-09-27 23:40:13 +02:00
parent c96377c9df
commit 15e7241807
No known key found for this signature in database
GPG key ID: 4A849A1904CCBD7D

View file

@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Perform operations on a card. Different states of a card are modeled by
//! different types, such as `Open`, `User`, `Sign`, `Admin`.
//! different types, such as `Card`, `Open`, `User`, `Sign`, `Admin`.
use sequoia_openpgp::cert::amalgamation::key::ValidErasedKeyAmalgamation;
use sequoia_openpgp::packet::key::SecretParts;
@ -15,7 +15,7 @@ use openpgp_card::card_do::{
SecuritySupportTemplate, Sex, TouchPolicy,
};
use openpgp_card::crypto_data::PublicKeyMaterial;
use openpgp_card::{Error, KeySet, KeyType, OpenPgpTransaction};
use openpgp_card::{CardBackend, Error, KeySet, KeyType, OpenPgp, OpenPgpTransaction};
use crate::decryptor::CardDecryptor;
use crate::signer::CardSigner;
@ -24,6 +24,30 @@ use crate::PublicKey;
/// Representation of an opened OpenPGP card in its base state (i.e. no
/// passwords have been verified, default authorization applies).
/// No transaction has been started.
pub struct Card {
pgp: OpenPgp,
}
impl Card {
pub fn new<B>(backend: B) -> Self
where
B: Into<Box<dyn CardBackend + Send + Sync>>,
{
let pgp = OpenPgp::new(backend.into());
Self { pgp }
}
pub fn transaction(&mut self) -> Result<Open, Error> {
let t = self.pgp.transaction()?;
Open::new(t)
}
}
/// Representation of an opened OpenPGP card in its base state (i.e. no
/// passwords have been verified, default authorization applies).
/// A transaction has been started.
pub struct Open<'a> {
opt: OpenPgpTransaction<'a>,