pub struct Authenticated<T> {
pub value: T,
pub protected: JoseHeader,
pub unprotected: Vec<Value>,
/* private fields */
}Expand description
A value that arrived under signature or AEAD authentication.
Fields are public because they are the answer, not because they are
interchangeable: protected was integrity-protected by the
operation that produced this value, and unprotected
explicitly was not. Use the protected header for any decision — algorithm, key
identity, content type, crit — and treat the unprotected entries as
display-only metadata.
Fields§
§value: TThe verified payload, plaintext, or parsed claims.
protected: JoseHeaderThe protected header that was authenticated with this value.
This is the header the signature covered (or the JWE protected header the AEAD tag authenticated), parsed once by the verification path. It is not a re-parse of whatever bytes the caller still has.
unprotected: Vec<Value>Unauthenticated metadata carried by the document, verbatim.
A compact JWS carries none, so this is usually empty. A flattened or general
JWS/JWE can carry several objects (the shared unprotected member plus a
header member per signature/recipient); each is one entry here, in the
order they appeared.
Never select a key, an algorithm, or a trust decision from these. They
are not integrity-protected: a document that verifies perfectly can carry a
hostile kid here.
Implementations§
Source§impl<T> Authenticated<T>
impl<T> Authenticated<T>
Sourcepub fn verified_key_index(&self) -> Option<usize>
pub fn verified_key_index(&self) -> Option<usize>
Index of the JWK that verified this token, relative to the supplied set.
This identifies the successful candidate even in a kid-less fallback.
It is not an identity or authorization claim. Single-key and JWE APIs
return None; Self::map preserves it.
Sourcepub fn into_value(self) -> T
pub fn into_value(self) -> T
Discard the header and keep the value.
Sourcepub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Authenticated<U>
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Authenticated<U>
Transform the value, keeping the header context.
Useful for parsing a verified payload into a domain type without losing the authenticated header next to it.
Sourcepub fn algorithm(&self) -> &str
pub fn algorithm(&self) -> &str
The authenticated alg value.
A convenience for the single most common header read after verification — and the reason it exists as a method is so that read does not have to reach for a header from somewhere else.
Sourcepub fn kid(&self) -> Option<&str>
pub fn kid(&self) -> Option<&str>
The kid from the authenticated header only.
Deliberately does not consult unprotected, unlike a
PlainHeader-style getter that would search every object it can find.
Sourcepub fn has_unprotected(&self) -> bool
pub fn has_unprotected(&self) -> bool
true when the document carried any unauthenticated metadata.
A caller that logs “this document tried to tell me something outside the signature” can gate on this.