#[non_exhaustive]pub struct StatusListToken {
pub sub: String,
pub iat: i64,
pub exp: Option<i64>,
pub ttl: Option<u64>,
pub status_list: StatusList,
pub additional: IndexMap<String, Value>,
}status-list only.Expand description
The claims of a status list token in JWT format (Token Status List §5.1).
§Examples
use chrono::{TimeZone as _, Utc};
use identity_kit::status_list::{StatusListRef, StatusListToken, StatusType};
use identity_kit::vc::Jwt;
// Token Status List §8.2.
let jwt: Jwt = "eyJhbGciOiJFUzI1NiIsImtpZCI6IjEyIiwidHlwIjoic3RhdHVzbGlzdCtqd3QifQ.e\
yJleHAiOjIyOTE3MjAxNzAsImlhdCI6MTY4NjkyMDE3MCwiaXNzIjoiaHR0cHM6Ly9leGFtcGxlLmNvbSIsInN0YXR1\
c19saXN0Ijp7ImJpdHMiOjEsImxzdCI6ImVOcmJ1UmdBQWhjQlhRIn0sInN1YiI6Imh0dHBzOi8vZXhhbXBsZS5jb20\
vc3RhdHVzbGlzdHMvMSIsInR0bCI6NDMyMDB9.2lKUUNG503R9htu4aHAYi7vjmr3sgApbfoDvPrl65N3URUO1EYqq\
Ql45Jfzd-Av4QzlKa3oVALpLwOEUOq-U_g".parse()?;
let (header, token) = StatusListToken::decode(&jwt)?;
assert_eq!(header.kid.as_deref(), Some("12"));
assert_eq!(token.sub, "https://example.com/statuslists/1");
assert_eq!(token.ttl, Some(43200));
let now = Utc.with_ymd_and_hms(2024, 1, 1, 0, 0, 0).unwrap();
let reference = StatusListRef::new("https://example.com/statuslists/1", 0);
assert_eq!(token.status_of(&reference, now)?, StatusType::INVALID);
assert_eq!(token.status_of(&StatusListRef::new(&reference.uri, 1), now)?, StatusType::VALID);
assert!(token.status_of(&StatusListRef::new(&reference.uri, 16), now).is_err());Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.sub: Stringsub: the URI of the token, the uri referenced tokens use.
iat: i64iat: when the token was issued. A NumericDate with a fraction is floored.
exp: Option<i64>exp: when the token expires. A NumericDate with a fraction is floored.
ttl: Option<u64>ttl: how many seconds the token may be cached.
status_list: StatusListstatus_list: the list.
additional: IndexMap<String, Value>Every other claim, in insertion order.
Implementations§
Source§impl StatusListToken
impl StatusListToken
Sourcepub const MEDIA_TYPE: &'static str = "application/statuslist+jwt"
pub const MEDIA_TYPE: &'static str = "application/statuslist+jwt"
The media type of a status list token, application/statuslist+jwt.
Sourcepub fn new(
sub: impl Into<String>,
iat: DateTime<Utc>,
status_list: StatusList,
) -> Self
pub fn new( sub: impl Into<String>, iat: DateTime<Utc>, status_list: StatusList, ) -> Self
A token for the list at sub, issued at iat.
Sourcepub fn with_expires_at(self, time: DateTime<Utc>) -> Self
pub fn with_expires_at(self, time: DateTime<Utc>) -> Self
This token with exp.
Sourcepub fn with_claim(
self,
name: impl Into<String>,
value: impl Into<Value>,
) -> Self
pub fn with_claim( self, name: impl Into<String>, value: impl Into<Value>, ) -> Self
This token with the claim name set to value.
Sourcepub fn decode(jwt: &Jwt) -> Result<(JwsHeader, Self), StatusListError>
pub fn decode(jwt: &Jwt) -> Result<(JwsHeader, Self), StatusListError>
Decodes jwt without verifying it: the header, whose typ must be
statuslist+jwt, and the claims.
§Errors
StatusListError::Jws, StatusListError::UnexpectedTyp or
StatusListError::Payload.
Sourcepub async fn sign(&self, signer: &dyn Signer) -> Result<Jwt, StatusListError>
pub async fn sign(&self, signer: &dyn Signer) -> Result<Jwt, StatusListError>
Signs this token with signer, typ: statuslist+jwt and the signer’s kid.
§Errors
StatusListError::Jws when signing fails.
§Panics
Never: the token always serializes to JSON, and the JWS is one this function has just encoded.
Sourcepub fn status_of(
&self,
reference: &StatusListRef,
now: DateTime<Utc>,
) -> Result<StatusType, StatusListError>
pub fn status_of( &self, reference: &StatusListRef, now: DateTime<Utc>, ) -> Result<StatusType, StatusListError>
The status of the token reference points at (Token Status List §8.3, steps 4 to 6):
sub must be the referenced URI, the token must not have expired at now, the index
must be in range.
§Errors
StatusListError::SubjectMismatch, StatusListError::Expired or
StatusListError::IndexOutOfRange.
Trait Implementations§
Source§impl Clone for StatusListToken
impl Clone for StatusListToken
Source§impl Debug for StatusListToken
impl Debug for StatusListToken
Source§impl<'de> Deserialize<'de> for StatusListToken
impl<'de> Deserialize<'de> for StatusListToken
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for StatusListToken
Source§impl PartialEq for StatusListToken
impl PartialEq for StatusListToken
Source§impl Serialize for StatusListToken
impl Serialize for StatusListToken
impl StructuralPartialEq for StatusListToken
Auto Trait Implementations§
impl Freeze for StatusListToken
impl RefUnwindSafe for StatusListToken
impl Send for StatusListToken
impl Sync for StatusListToken
impl Unpin for StatusListToken
impl UnsafeUnpin for StatusListToken
impl UnwindSafe for StatusListToken
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.