CharterAgreementProtocol.Digest (Charter Agreement Protocol v0.1.0)

Copy Markdown View Source

CAP never authorizes.

Tagged SHA-256 content digests over canonical bytes.

Preimages are separator || <<0>> || bytes; the wire form is sha-256:<43-character unpadded base64url>. Equality consumes every byte pair through an XOR accumulator and tests only once at the end.

Summary

Functions

Compare fixed-width digest bytes without an early content exit.

Parse a closed tagged digest string.

Hash bytes under a registered domain separator. Unknown domains raise.

Hash arbitrary iodata with SHA-256.

Encode a fixed-width digest in tagged wire form.

Verify a tagged digest against bytes under a registered domain.

Types

algorithm()

@type algorithm() :: :sha256

t()

@type t() :: %CharterAgreementProtocol.Digest{
  algorithm: algorithm(),
  bytes: <<_::256>>
}

Functions

equal?(arg1, arg2)

@spec equal?(term(), term()) :: boolean()

Compare fixed-width digest bytes without an early content exit.

from_tagged(input)

@spec from_tagged(term()) :: {:ok, t()} | {:error, CharterAgreementProtocol.Error.t()}

Parse a closed tagged digest string.

hash(domain, data)

@spec hash(atom(), iodata()) :: t()

Hash bytes under a registered domain separator. Unknown domains raise.

of(data)

@spec of(iodata()) :: t()

Hash arbitrary iodata with SHA-256.

to_tagged(digest)

@spec to_tagged(t()) :: binary()

Encode a fixed-width digest in tagged wire form.

verify_content(domain, bytes, tagged)

@spec verify_content(atom(), binary(), term()) ::
  :ok | {:error, CharterAgreementProtocol.Error.t()}

Verify a tagged digest against bytes under a registered domain.