identity_credential/credential/
refresh.rs

1// Copyright 2020-2022 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::OneOrMany;
9use identity_core::common::Url;
10
11/// Information used to refresh or assert the status of a [`Credential`][crate::credential::Credential].
12///
13/// [More Info](https://www.w3.org/TR/vc-data-model/#refreshing)
14#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
15pub struct RefreshService {
16  /// The Url of the credential refresh service.
17  pub id: Url,
18  /// The type(s) of the credential refresh service.
19  #[serde(rename = "type")]
20  pub types: OneOrMany<String>,
21  /// Additional properties of the credential refresh service.
22  #[serde(flatten)]
23  pub properties: Object,
24}
25
26impl RefreshService {
27  /// Creates a new `RefreshService`.
28  pub fn new<T>(id: Url, types: T) -> Self
29  where
30    T: Into<OneOrMany<String>>,
31  {
32    Self::with_properties(id, types, Object::new())
33  }
34
35  /// Creates a new `RefreshService` with the given `properties`.
36  pub fn with_properties<T>(id: Url, types: T, properties: Object) -> Self
37  where
38    T: Into<OneOrMany<String>>,
39  {
40    Self {
41      id,
42      types: types.into(),
43      properties,
44    }
45  }
46}
47
48#[cfg(test)]
49mod tests {
50  use identity_core::convert::FromJson;
51
52  use crate::credential::RefreshService;
53
54  const JSON: &str = include_str!("../../tests/fixtures/refresh-1.json");
55
56  #[test]
57  fn test_from_json() {
58    let service: RefreshService = RefreshService::from_json(JSON).unwrap();
59    assert_eq!(service.id, "https://example.edu/refresh/3732");
60    assert_eq!(service.types.as_slice(), ["ManualRefreshService2018"]);
61  }
62}