identity_credential/presentation/
jwt_presentation_options.rs

1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use identity_core::common::Object;
5use serde::Deserialize;
6use serde::Serialize;
7
8use identity_core::common::Timestamp;
9use identity_core::common::Url;
10
11/// Options to be set in the JWT claims of a verifiable presentation.
12#[derive(Clone, Debug, Serialize, Deserialize)]
13#[serde(rename_all = "camelCase")]
14pub struct JwtPresentationOptions {
15  /// Set the presentation's expiration date.
16  /// Default: `None`.
17  pub expiration_date: Option<Timestamp>,
18  /// Set the issuance date.
19  /// Default: current datetime.
20  pub issuance_date: Option<Timestamp>,
21  /// Sets the audience for presentation (`aud` property in JWT claims).
22  /// Default: `None`.
23  pub audience: Option<Url>,
24  /// Custom claims that can be used to set additional claims on the resulting JWT.
25  pub custom_claims: Option<Object>,
26}
27
28impl JwtPresentationOptions {
29  /// Set the presentation's expiration date.
30  pub fn expiration_date(mut self, expires: Timestamp) -> Self {
31    self.expiration_date = Some(expires);
32    self
33  }
34
35  /// Set the issuance date.
36  pub fn issuance_date(mut self, issued_at: Timestamp) -> Self {
37    self.issuance_date = Some(issued_at);
38    self
39  }
40
41  /// Sets the audience for presentation (`aud` property in JWT claims).
42  pub fn audience(mut self, audience: Url) -> Self {
43    self.audience = Some(audience);
44    self
45  }
46}
47
48impl Default for JwtPresentationOptions {
49  fn default() -> Self {
50    Self {
51      expiration_date: None,
52      issuance_date: Some(Timestamp::now_utc()),
53      audience: None,
54      custom_claims: None,
55    }
56  }
57}