use sett::openpgp::{
cert::{Cert, CertType},
keystore::KeyStore,
types::SerializationFormat,
};
#[tokio::test]
async fn export_secret() -> anyhow::Result<()> {
let mut key_store = KeyStore::open_ephemeral().await?;
let pub_cert_ref = Cert::from_bytes(include_bytes!(
"./data/1EA0292ECBF2457CADAE20E2B94FA6A56D9FA1FB.pub"
))?;
assert!(matches!(pub_cert_ref.cert_type(), CertType::Public));
let updated_cert = pub_cert_ref
.clone()
.update_secret_material(&mut key_store)
.await;
assert!(updated_cert.is_err());
assert!(updated_cert
.unwrap_err()
.to_string()
.starts_with("No secret material was found "));
let sec_cert_ref = Cert::from_bytes(include_bytes!(
"./data/1EA0292ECBF2457CADAE20E2B94FA6A56D9FA1FB.sec"
))?;
key_store.import(sec_cert_ref.clone()).await?;
let updated_cert = pub_cert_ref
.clone()
.update_secret_material(&mut key_store)
.await?;
assert!(matches!(updated_cert.cert_type(), CertType::Secret));
assert_eq!(
updated_cert.serialize(CertType::Secret, SerializationFormat::Binary)?,
sec_cert_ref.serialize(CertType::Secret, SerializationFormat::Binary)?
);
Ok(())
}