Sovite.DKIM.Key (sovite v0.6.0)

Copy Markdown View Source

DKIM public keys: the key records published at <selector>._domainkey.<domain> (RFC 6376 §3.6.1), and the signature algorithms that use them.

RSA keys shorter than 1024 bits are refused (RFC 8301 §3.2). Ed25519 keys are the raw 32 bytes (RFC 8463 §4.2).

Summary

Types

Why no key could be used: permanent, or a DNS failure.

t()

A public key. key is an RSAPublicKey record or the raw Ed25519 key; strict is t=s: the i= domain must equal d=.

Functions

Looks up the key for selector and domain. When several records are published, the first usable one counts.

Parses a key record.

Checks signature over data with key, for algorithm. For Ed25519 the SHA-256 hash of the data is what is signed (RFC 8463 §3).

Types

error()

@type error() :: {:permerror, String.t()} | {:temperror, String.t()}

Why no key could be used: permanent, or a DNS failure.

t()

@type t() :: %Sovite.DKIM.Key{
  bits: pos_integer() | nil,
  key: tuple() | binary(),
  strict: boolean(),
  type: :rsa | :ed25519
}

A public key. key is an RSAPublicKey record or the raw Ed25519 key; strict is t=s: the i= domain must equal d=.

Functions

fetch(resolver, selector, domain)

@spec fetch(Sovite.DNS.resolver(), String.t(), String.t()) ::
  {:ok, t()} | {:error, error()}

Looks up the key for selector and domain. When several records are published, the first usable one counts.

parse(record)

@spec parse(String.t()) :: {:ok, t()} | {:error, String.t()}

Parses a key record.

iex> {:ok, key} = Sovite.DKIM.Key.parse("v=DKIM1; k=ed25519; p=11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=")
iex> key.type
:ed25519

verify(key, arg2, data, signature)

@spec verify(t(), Sovite.DKIM.Signature.algorithm(), iodata(), binary()) :: boolean()

Checks signature over data with key, for algorithm. For Ed25519 the SHA-256 hash of the data is what is signed (RFC 8463 §3).