identity_credential/credential/
status.rs

1// Copyright 2020-2021 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use serde::Deserialize;
5use serde::Serialize;
6
7use identity_core::common::Object;
8use identity_core::common::Url;
9
10/// Information used to determine the current status of a [`Credential`][crate::credential::Credential].
11///
12/// [More Info](https://www.w3.org/TR/vc-data-model/#status)
13#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
14pub struct Status<T = Object> {
15  /// A Url identifying the credential status.
16  pub id: Url,
17  /// The type(s) of the credential status.
18  #[serde(rename = "type")]
19  pub type_: String,
20  /// Additional properties of the credential status.
21  #[serde(flatten)]
22  pub properties: T,
23}
24
25impl Status<Object> {
26  /// Creates a new `Status`.
27  pub fn new(id: Url, type_: String) -> Self {
28    Self::new_with_properties(id, type_, Object::new())
29  }
30}
31
32impl<T> Status<T> {
33  /// Creates a new `Status` with the given `properties`.
34  pub fn new_with_properties(id: Url, type_: String, properties: T) -> Self {
35    Self { id, type_, properties }
36  }
37}
38
39#[cfg(test)]
40mod tests {
41  use identity_core::convert::FromJson;
42
43  use super::*;
44
45  const JSON: &str = include_str!("../../tests/fixtures/status-1.json");
46
47  #[test]
48  fn test_from_json() {
49    let status: Status = Status::from_json(JSON).unwrap();
50    assert_eq!(status.id.as_str(), "https://example.edu/status/24");
51    assert_eq!(status.type_, "CredentialStatusList2017");
52  }
53}