identity_credential/sd_jwt_vc/
status.rs

1// Copyright 2020-2024 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use identity_core::common::Url;
5use serde::Deserialize;
6use serde::Serialize;
7
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9/// SD-JWT VC's `status` claim value. Used to retrieve the status of the token.
10pub struct Status(StatusMechanism);
11
12/// Mechanism used for representing the status of an SD-JWT VC token.
13#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
14#[non_exhaustive]
15pub enum StatusMechanism {
16  /// Reference to a status list containing this token's status.
17  #[serde(rename = "status_list")]
18  StatusList(StatusListRef),
19  /// A non-standard status mechanism.
20  #[serde(untagged)]
21  Custom(serde_json::Value),
22}
23
24#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
25/// A reference to an OAuth status list.
26/// See [OAuth StatusList specification](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-status-list-02)
27/// for more information.
28pub struct StatusListRef {
29  /// URI of the status list.
30  pub uri: Url,
31  /// Index of the entry containing this token's status.
32  pub idx: usize,
33}
34
35#[cfg(test)]
36mod tests {
37  use super::*;
38
39  use serde_json::json;
40
41  #[test]
42  fn round_trip() {
43    let status_value = json!({
44      "status_list": {
45        "idx": 420,
46        "uri": "https://example.com/statuslists/1"
47      }
48    });
49    let status: Status = serde_json::from_value(status_value.clone()).unwrap();
50    assert_eq!(serde_json::to_value(status).unwrap(), status_value);
51  }
52}