Sovite.DKIM.Canon (sovite v0.6.0)

Copy Markdown View Source

Header canonicalization (RFC 6376 §3.4.1 and §3.4.2), and the header data a signature covers (§3.7, §5.4.2).

Body canonicalization works on a stream, see Sovite.DKIM.Body.

Summary

Functions

Canonicalizes one header field, given as its raw text with the final CRLF.

Selects the fields named in names (a signature's h= tag), as §5.4.2 says: each occurrence of a name takes the next instance from the bottom of the header; a name with no instance left adds nothing.

The data that is hashed and signed: the selected fields, canonicalized, then the signature field itself with its b= value emptied and no final CRLF.

Types

algorithm()

@type algorithm() :: :simple | :relaxed

Functions

header(raw, atom)

@spec header(String.t(), algorithm()) :: String.t()

Canonicalizes one header field, given as its raw text with the final CRLF.

iex> Sovite.DKIM.Canon.header("SubJect :  Hello \r\n  world  \r\n", :relaxed)
"subject:Hello world\r\n"

select(fields, names)

@spec select([{String.t() | nil, String.t()}], [String.t()]) :: [String.t()]

Selects the fields named in names (a signature's h= tag), as §5.4.2 says: each occurrence of a name takes the next instance from the bottom of the header; a name with no instance left adds nothing.

fields are as Sovite.Message.Headers.parse/1 returns them.

signed_data(selected, signature_raw, algorithm)

@spec signed_data([String.t()], String.t(), algorithm()) :: iodata()

The data that is hashed and signed: the selected fields, canonicalized, then the signature field itself with its b= value emptied and no final CRLF.