Shared mechanics for claim-key normalization and registered-claim merging.
Protocol modules retain ownership of their registered-claim policy. This module only makes the map-key boundary explicit before a claim map is serialized or merged.
Summary
Functions
Compare an audience claim with an expected audience under an explicit protocol mode.
Merge caller-supplied claims into authoritative registered claims.
Normalize the keys in map to JSON member-name binaries.
Match a JOSE typ value against an explicit accepted set using the
RFC 7515 application/ bare-subtype convention.
Types
@type atom_policy() :: :reject | :convert
@type audience_mode() :: :scalar_only | :array | :single_element | :all_array_members
@type normalize_error() :: {:invalid_key, term()} | :invalid_atom_policy
Functions
@spec audience_matches?(term(), term(), audience_mode()) :: boolean()
Compare an audience claim with an expected audience under an explicit protocol mode.
The caller must select the mode because audience forms are protocol policy, not a single shared rule:
:scalar_onlyaccepts only a binary claim.:arrayaccepts a binary claim or a non-empty all-binary array with intersection semantics.:single_elementaccepts a scalar or exactly[expected].:all_array_membersrequires every member of an array to be expected.
This is a value-level predicate; callers retain responsibility for error mapping and any surrounding claim validation.
@spec merge_registered(map(), map(), keyword()) :: {:ok, map()} | {:error, normalize_error() | :reserved_claim_conflict}
Merge caller-supplied claims into authoritative registered claims.
The caller map is normalized first. Keys in reserved are rejected before
the merge; by default every key already present in registered is reserved.
atom_keys is passed to normalize_keys/2 as its :atoms policy.
@spec normalize_keys( map(), keyword() ) :: {:ok, map()} | {:error, normalize_error()}
Normalize the keys in map to JSON member-name binaries.
With atoms: :reject (the default), every key must already be a binary.
With atoms: :convert, atom keys are converted with Atom.to_string/1;
all other non-binary keys are rejected.
Match a JOSE typ value against an explicit accepted set using the
RFC 7515 application/ bare-subtype convention.
The normalization option is intentionally required. Callers with exact or otherwise protocol-specific type rules must keep those rules local.