identity_credential/validator/jwt_presentation_validation/
jwt_presentation_validation_options.rs

1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use serde::Deserialize;
5use serde::Serialize;
6
7use identity_core::common::Timestamp;
8use identity_document::verifiable::JwsVerificationOptions;
9
10/// Criteria for validating a [`Presentation`](crate::presentation::Presentation).
11#[derive(Debug, Default, Clone, Serialize, Deserialize)]
12#[non_exhaustive]
13#[serde(rename_all = "camelCase")]
14pub struct JwtPresentationValidationOptions {
15  /// Options which affect the verification of the signature on the presentation.
16  #[serde(default)]
17  pub presentation_verifier_options: JwsVerificationOptions,
18
19  /// Declares that the presentation is **not** considered valid if it expires before this
20  /// [`Timestamp`].
21  /// Uses the current datetime during validation if not set.
22  #[serde(default)]
23  pub earliest_expiry_date: Option<Timestamp>,
24
25  /// Declares that the presentation is **not** considered valid if it was issued later than this
26  /// [`Timestamp`].
27  /// Uses the current datetime during validation if not set.
28  #[serde(default)]
29  pub latest_issuance_date: Option<Timestamp>,
30}
31
32impl JwtPresentationValidationOptions {
33  /// Constructor that sets all options to their defaults.
34  pub fn new() -> Self {
35    Self::default()
36  }
37
38  /// Set options which affect the verification of the signature on the presentation.
39  pub fn presentation_verifier_options(mut self, options: JwsVerificationOptions) -> Self {
40    self.presentation_verifier_options = options;
41    self
42  }
43
44  /// Declare that the presentation is **not** considered valid if it expires before this [`Timestamp`].
45  /// Uses the current datetime during validation if not set.
46  pub fn earliest_expiry_date(mut self, timestamp: Timestamp) -> Self {
47    self.earliest_expiry_date = Some(timestamp);
48    self
49  }
50
51  /// Declare that the presentation is **not** considered valid if it was issued later than this [`Timestamp`].
52  /// Uses the current datetime during validation if not set.
53  pub fn latest_issuance_date(mut self, timestamp: Timestamp) -> Self {
54    self.latest_issuance_date = Some(timestamp);
55    self
56  }
57}