This module creates, parses, and compares tagged SHA-256 digests.
Use it when computing or checking a digest over canonical bytes.
This module does not authorize operations.
Example
match?(
"sha-256:" <> _,
AgentBlueprintProtocol.Digest.to_tagged(
AgentBlueprintProtocol.Digest.hash(:blueprint_content, "{}")
)
)
Summary
Types
The digest algorithm identifier supported by this release.
A closed digest domain used to separate protocol digest inputs.
The public data type for AgentBlueprintProtocol.Digest.
Functions
Compares two values for equality under this module’s rules.
Parses a tagged digest string.
Creates a domain-separated digest from the supplied bytes.
Creates a SHA-256 digest from the supplied bytes.
Formats a digest as its tagged wire string.
Checks a tagged digest against the supplied content and domain.
Types
@type algorithm() :: :sha256
The digest algorithm identifier supported by this release.
@type domain() ::
:blueprint_content
| :deployment_content
| :federation_envelope
| :signature
| :extension_schema
| :extension_registry
| :conformance_report
| :corpus_index
A closed digest domain used to separate protocol digest inputs.
@type t() :: %AgentBlueprintProtocol.Digest{algorithm: algorithm(), bytes: <<_::256>>}
The public data type for AgentBlueprintProtocol.Digest.
Functions
Compares two values for equality under this module’s rules.
Example
iex> AgentBlueprintProtocol.Digest.equal?(AgentBlueprintProtocol.Digest.hash(:signature, "input"), AgentBlueprintProtocol.Digest.hash(:signature, "input"))
true
@spec from_tagged(binary()) :: {:ok, t()} | {:error, AgentBlueprintProtocol.Error.t()}
Parses a tagged digest string.
Example
iex> match?({:ok, %AgentBlueprintProtocol.Digest{algorithm: :sha256}}, AgentBlueprintProtocol.Digest.from_tagged("sha-256:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))
true
@spec hash(domain(), iodata()) :: t() | {:error, AgentBlueprintProtocol.Error.t()}
Creates a domain-separated digest from the supplied bytes.
Example
iex> match?(%AgentBlueprintProtocol.Digest{algorithm: :sha256, bytes: <<_::256>>}, AgentBlueprintProtocol.Digest.hash(:blueprint_content, "{}"))
true
@spec of(iodata()) :: t() | {:error, AgentBlueprintProtocol.Error.t()}
Creates a SHA-256 digest from the supplied bytes.
Example
iex> match?(%AgentBlueprintProtocol.Digest{algorithm: :sha256, bytes: <<_::256>>}, AgentBlueprintProtocol.Digest.of("abc"))
true
@spec to_tagged(t()) :: binary() | {:error, AgentBlueprintProtocol.Error.t()}
Formats a digest as its tagged wire string.
Example
iex> digest = AgentBlueprintProtocol.Digest.hash(:blueprint_content, "{}")
iex> String.starts_with?(AgentBlueprintProtocol.Digest.to_tagged(digest), "sha-256:")
true
@spec verify_content(domain(), binary(), binary()) :: :ok | {:error, AgentBlueprintProtocol.Error.t()}
Checks a tagged digest against the supplied content and domain.
Example
iex> bytes = "{}"; tagged = AgentBlueprintProtocol.Digest.hash(:blueprint_content, bytes) |> AgentBlueprintProtocol.Digest.to_tagged(); AgentBlueprintProtocol.Digest.verify_content(:blueprint_content, bytes, tagged)
:ok