Sovite.DKIM.Body (sovite v0.6.0)

Copy Markdown View Source

Body hashes (RFC 6376 §3.4.3, §3.4.4, §3.7), computed while the body streams by, for any number of signatures at once.

body = Sovite.DKIM.Body.new([{:relaxed, :sha256, nil}, {:simple, :sha256, 100}])
body = Sovite.DKIM.Body.update(body, chunk)
%{{:relaxed, :sha256, nil} => {hash, length}} = Sovite.DKIM.Body.finish(body)

A spec is the body canonicalization, the hash, and the l= length limit (nil for the whole body). Each canonicalization is done once, however many specs use it. finish/1 returns each hash with the length of the whole canonicalized body, so a verifier can tell an l= larger than the body.

The body is the data after the empty line that ends the header section, with CRLF line endings.

Summary

Functions

Ends the body. Returns each spec's hash and the canonicalized body length.

Starts hashing for specs.

Feeds body data.

Types

spec()

@type spec() :: {Sovite.DKIM.Canon.algorithm(), :sha256, non_neg_integer() | nil}

t()

@opaque t()

Functions

finish(body)

@spec finish(t()) :: %{required(spec()) => {binary(), non_neg_integer()}}

Ends the body. Returns each spec's hash and the canonicalized body length.

new(specs)

@spec new([spec()]) :: t()

Starts hashing for specs.

update(body, data)

@spec update(t(), iodata()) :: t()

Feeds body data.