mail_auth/signer.rs
1/*
2 * SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <hello@stalw.art>
3 *
4 * SPDX-License-Identifier: Apache-2.0 OR MIT
5 */
6
7//! Typestate markers for the signer builders.
8//!
9//! [`DkimSigner`](crate::dkim::DkimSigner), `ArcSealer` (feature `arc`) and
10//! [`Dkim2Signer`](crate::dkim2::Dkim2Signer) carry one of these markers as
11//! a type parameter. Each builder method consumes the signer and returns it in
12//! the next state, so the compiler rejects a signer that is used before every
13//! mandatory field is set:
14//!
15//! - `DkimSigner` and `ArcSealer`: [`NeedDomain`] (after `from_key`), then
16//! [`NeedSelector`] (after `domain`), then [`NeedHeaders`] (after
17//! `selector`), then [`Ready`] (after `headers`).
18//! - `Dkim2Signer`: [`NeedDomain`], then [`NeedSelector`], then [`Ready`]
19//! (after `selector`). DKIM2 does not take a list of signed headers.
20//!
21//! Only a signer in the [`Ready`] state exposes the optional setters and the
22//! signing methods. The markers are zero-sized and carry no data.
23
24/// The signer has a key but no signing domain (`d=` tag) yet.
25#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
26pub struct NeedDomain;
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
29/// The signer has a signing domain but no selector (`s=` tag) yet.
30pub struct NeedSelector;
31
32#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
33/// The signer has a domain and selector but no list of headers to sign
34/// (`h=` tag) yet. Used by `DkimSigner` and `ArcSealer` only.
35pub struct NeedHeaders;
36
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
38/// Every mandatory field is set; the signer can sign messages.
39pub struct Ready;