use sett::openpgp::{
cert::{Cert, CertType},
keystore::KeyStore,
};
#[tokio::test]
async fn export_secret() {
let mut key_store = KeyStore::open_ephemeral().await.unwrap();
let pub_cert_ref = Cert::from_bytes(include_bytes!(
"./data/1EA0292ECBF2457CADAE20E2B94FA6A56D9FA1FB.pub"
))
.unwrap();
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"
))
.unwrap();
key_store.import(sec_cert_ref.clone()).await.unwrap();
let updated_cert = pub_cert_ref
.clone()
.update_secret_material(&mut key_store)
.await
.unwrap();
assert!(matches!(updated_cert.cert_type(), CertType::Secret));
assert_eq!(
Vec::<u8>::try_from(updated_cert.secret().unwrap()).unwrap(),
Vec::<u8>::try_from(sec_cert_ref.secret().unwrap()).unwrap()
);
}