use anyhow::Result;
use sequoia_openpgp::cert::Cert;
use sequoia_openpgp::crypto::Signer;
use crate::backend::CertificationBackend;
use crate::pgp;
pub(crate) struct SoftkeyBackend {
ca_cert: Cert,
}
impl SoftkeyBackend {
pub(crate) fn new(ca_cert: Cert) -> Self {
Self { ca_cert }
}
}
impl CertificationBackend for SoftkeyBackend {
fn certify(&self, op: &mut dyn FnMut(&mut dyn Signer) -> Result<()>) -> Result<()> {
let ca_keys = pgp::get_cert_keys(&self.ca_cert, None);
for mut s in ca_keys {
op(&mut s as &mut dyn Signer)?;
}
Ok(())
}
fn sign(&self, op: &mut dyn FnMut(&mut dyn Signer) -> Result<()>) -> Result<()> {
let mut signing_keypair = self
.ca_cert
.clone()
.keys()
.secret()
.with_policy(pgp::SP, None)
.supported()
.alive()
.revoked(false)
.for_signing()
.next()
.unwrap()
.key()
.clone()
.into_keypair()?;
op(&mut signing_keypair as &mut dyn Signer)?;
Ok(())
}
}