Steps towards encryption
- Added certstore and retrieval of the local trust root. - Major work on keeping the context between calls to the milter. - Added a context for an email in processing - Added Husk specific errors
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Husk milter
|
||||
//
|
||||
// cryptographic functions
|
||||
//
|
||||
|
||||
use anyhow;
|
||||
use sequoia_openpgp::parse::Parse;
|
||||
use sequoia_openpgp::{Fingerprint, Cert};
|
||||
use sequoia_openpgp::cert::raw::RawCertParser;
|
||||
use sequoia_cert_store::CertStore;
|
||||
use crate::types::errors::HuskError;
|
||||
|
||||
pub fn get_local_trust_root(cert_store: &CertStore) -> anyhow::Result<Cert> {
|
||||
|
||||
let root = cert_store.certd()
|
||||
.and_then(|certd| {
|
||||
match certd.certd().get(sequoia_cert_store::store::openpgp_cert_d::TRUST_ROOT) {
|
||||
Ok(Some((_tag, bytes))) => Some(bytes),
|
||||
Ok(None) => None,
|
||||
Err(_) => None
|
||||
}
|
||||
})
|
||||
.and_then(|bytes| {
|
||||
match RawCertParser::from_bytes(&bytes[..]) {
|
||||
Ok(mut parser) => {
|
||||
match parser.next() {
|
||||
Some(Ok(cert)) => {
|
||||
match Cert::from_bytes(cert.as_bytes()) {
|
||||
Ok(c) => Some(c),
|
||||
Err(_) => None,
|
||||
}
|
||||
},
|
||||
Some(Err(_))
|
||||
| None => None
|
||||
}
|
||||
},
|
||||
Err(_) => None,
|
||||
}
|
||||
});
|
||||
|
||||
match root {
|
||||
Some(r) => Ok(r),
|
||||
None => Err(HuskError::NoLocalTrustRoot.into())
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user