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,15 @@
|
||||
//
|
||||
// Husk milter
|
||||
//
|
||||
// Error typ
|
||||
//
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum HuskError {
|
||||
#[error("Cannot find local trust root")]
|
||||
NoLocalTrustRoot,
|
||||
#[error("Cannot access cert store")]
|
||||
NoCertStore
|
||||
}
|
||||
@@ -4,21 +4,41 @@
|
||||
// Context
|
||||
//
|
||||
|
||||
pub struct HuskContext {
|
||||
pub sender: Option<String>,
|
||||
use anyhow;
|
||||
use std::path::PathBuf;
|
||||
use sequoia_openpgp::Cert;
|
||||
use sequoia_cert_store::CertStore;
|
||||
use sequoia_directories::Home;
|
||||
|
||||
use crate::{config::HuskConfig, crypto};
|
||||
use crate::types::mail_context::MailContext;
|
||||
|
||||
pub struct HuskContext<'hc> {
|
||||
pub cert_store: CertStore<'hc>,
|
||||
pub local_trust_root: Cert,
|
||||
pub mail: MailContext<'hc>,
|
||||
}
|
||||
|
||||
impl HuskContext {
|
||||
|
||||
impl<'hc> HuskContext<'hc> {
|
||||
|
||||
/// Create a new HuskContext instance
|
||||
pub fn new() -> Option<HuskContext> {
|
||||
Some(HuskContext {
|
||||
sender: None
|
||||
pub fn new(config: &HuskConfig) -> anyhow::Result<HuskContext<'hc>> {
|
||||
|
||||
let sequoia_home = Home::new(PathBuf::from(&config.sequoia_home))?;
|
||||
let cert_store_base = sequoia_home.data_dir(sequoia_directories::Component::CertD);
|
||||
let cert_store = CertStore::open(cert_store_base)?;
|
||||
|
||||
let local_trust_root = crypto::get_local_trust_root(&cert_store)?;
|
||||
|
||||
Ok(HuskContext {
|
||||
cert_store,
|
||||
local_trust_root,
|
||||
mail: MailContext::new(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_sender(&mut self, sender: String) {
|
||||
self.sender = Some(sender);
|
||||
self.mail.set_sender(sender);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// Husk milter
|
||||
//
|
||||
// Mail Context
|
||||
//
|
||||
|
||||
use std::ffi::CString;
|
||||
|
||||
use sequoia_openpgp::cert::ValidCert;
|
||||
|
||||
pub struct Recipient<'r> {
|
||||
pub email: CString,
|
||||
pub cert: Option<ValidCert<'r>>,
|
||||
}
|
||||
|
||||
pub struct MailContext<'c> {
|
||||
pub sender: Option<String>,
|
||||
pub recipients: Vec<Recipient<'c>>,
|
||||
// header
|
||||
// body
|
||||
// body size
|
||||
}
|
||||
|
||||
impl MailContext<'_> {
|
||||
|
||||
pub fn new() -> Self {
|
||||
MailContext {
|
||||
sender: None,
|
||||
recipients: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_sender(&mut self, sender: String) {
|
||||
self.sender = Some(sender);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +1,3 @@
|
||||
pub mod husk_context;
|
||||
pub mod mail_context;
|
||||
pub mod errors;
|
||||
|
||||
Reference in New Issue
Block a user