Add certificates

- Refactor `Recipient` out of `MailContext`.
- Add lookup of authenticated certificates for recipients.
This commit is contained in:
Malte Meiboom
2025-12-11 16:03:34 +01:00
parent 23c698f445
commit dd71b89485
6 changed files with 92 additions and 24 deletions
+4 -1
View File
@@ -51,7 +51,10 @@ impl<'hc> HuskContext<'hc> {
}
pub fn add_recipient(&mut self, rcpt: String) -> anyhow::Result<()> {
self.mail.add_recipient(rcpt)
let certs = crypto::get_certificates(&self, rcpt.as_str());
self.mail.add_recipient(rcpt, certs)
}
}
+9 -22
View File
@@ -4,34 +4,20 @@
// Mail Context
//
use anyhow;
use std::sync::Arc;
use sequoia_cert_store::LazyCert;
use sequoia_openpgp::cert::ValidCert;
use crate::types::recipient::Recipient;
#[derive(Debug, Clone)]
pub struct Recipient<'r> {
pub email: String,
pub cert: Option<ValidCert<'r>>,
}
impl From<String> for Recipient<'_> {
fn from(email: String) -> Self {
Recipient {
email: email,
cert: None
}
}
}
pub struct MailContext<'c> {
pub struct MailContext<'mc> {
pub sender: Option<String>,
pub recipients: Vec<Recipient<'c>>,
pub recipients: Vec<Recipient<'mc>>,
// header
// body
// body size
}
impl MailContext<'_> {
impl<'mc> MailContext<'mc> {
pub fn new() -> Self {
MailContext {
@@ -44,8 +30,9 @@ impl MailContext<'_> {
self.sender = Some(sender);
}
pub fn add_recipient(&mut self, rcpt: String) -> anyhow::Result<()> {
let recipient: Recipient = rcpt.into();
pub fn add_recipient(&mut self, rcpt: String, certs: Vec<Arc<LazyCert<'mc>>>) -> anyhow::Result<()> {
let mut recipient: Recipient = rcpt.into();
recipient.certs = certs;
self.recipients.push(recipient);
+1
View File
@@ -1,3 +1,4 @@
pub mod husk_context;
pub mod mail_context;
pub mod errors;
pub mod recipient;
+39
View File
@@ -0,0 +1,39 @@
//
// Husk milter
//
// Recipient
//
use anyhow;
use std::sync::Arc;
use std::ffi::CString;
use sequoia_cert_store::LazyCert;
#[derive(Debug, Clone)]
pub struct Recipient<'r> {
pub email: String,
pub certs: Vec<Arc<LazyCert<'r>>>
}
impl From<String> for Recipient<'_> {
fn from(email: String) -> Self {
Recipient {
email: email,
certs: Vec::new()
}
}
}
impl TryFrom<CString> for Recipient<'_> {
type Error=anyhow::Error;
fn try_from(value: CString) -> Result<Self, Self::Error> {
match value.into_string() {
Ok(s) => Ok(s.into()),
Err(e) => Err(e.into()),
}
}
}