mirror of
https://github.com/mailscope/kumomta.git
synced 2026-10-27 08:46:13 +00:00
It is rather difficult to reuse the Signer in a dynamic application with the lifetime present in the struct. This commit removes the lifetime to make it easier to cache and reuse. The logger has also been removed from the API for the signer. It was used only in one place to log a single debug line, and it is a bit of an imposition on the embedding application to require the use of the `slog` crate just for that, and its removal helps with the goal of removing lifetimes from the struct as well. Some builder methods have been made a little more ergonomic by accepting values that are convertible to String rather than requiring str references. Since this commit changes the API signature, it also bumps the version from 0.2 to 0.3.
1.4 KiB
1.4 KiB
cfdkim
DKIM (RFC6376) implementation
Features
Verifying email signatures
Example:
let res: DKIMResult = cfdkim::verify_email(&logger, &from_domain, &parsed_email).await?;
if let Some(err) = &res.error() {
error!(logger, "dkim verify fail: {}", err);
}
println!("dkim={}", res.with_detail());
The verify_email arguments are the following:
Signing an email
Example:
let private_key =
rsa::RsaPrivateKey::read_pkcs1_pem_file(Path::new("./test/keys/2022.private"))?;
let signer = SignerBuilder::new()
.with_signed_headers(["From", "Subject"])?
.with_private_key(private_key)
.with_selector("2020")
.with_signing_domain("example.com")
.build()?;
let signature = signer.sign(&email)?;
println!("{}", signature); // DKIM-Signature: ...
See the SignerBuilder object documentation for more information.
Generate a test DKIM key
Using OpenDKIM:
opendkim-genkey \
--testmode \
--domain=example.com \
--selector=2022 \
--nosubdomains