identity_credential/validator/jpt_credential_validation/
jpt_credential_validation_options.rs

1// Copyright 2020-2024 IOTA Stiftung, Fondazione Links
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::validator::SubjectHolderRelationship;
5use identity_core::common::Timestamp;
6use identity_core::common::Url;
7use identity_document::verifiable::JwpVerificationOptions;
8use serde::Deserialize;
9use serde::Serialize;
10
11/// Options to declare validation criteria for [`Credential`](crate::credential::Credential)s.
12#[non_exhaustive]
13#[derive(Debug, Default, Clone, Serialize, Deserialize)]
14#[serde(rename_all = "camelCase")]
15pub struct JptCredentialValidationOptions {
16  /// Declares that the credential is **not** considered valid if it expires before this
17  /// [`Timestamp`].
18  /// Uses the current datetime during validation if not set.
19  #[serde(default)]
20  pub earliest_expiry_date: Option<Timestamp>,
21
22  /// Declares that the credential is **not** considered valid if it was issued later than this
23  /// [`Timestamp`].
24  /// Uses the current datetime during validation if not set.
25  #[serde(default)]
26  pub latest_issuance_date: Option<Timestamp>,
27
28  /// Validation behaviour for [`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status).
29  ///
30  /// Default: [`StatusCheck::Strict`](crate::validator::StatusCheck::Strict).
31  #[serde(default)]
32  pub status: crate::validator::StatusCheck,
33
34  /// Declares how credential subjects must relate to the presentation holder during validation.
35  ///
36  /// <https://www.w3.org/TR/vc-data-model/#subject-holder-relationships>
37  pub subject_holder_relationship: Option<(Url, SubjectHolderRelationship)>,
38
39  /// Options which affect the verification of the proof on the credential.
40  #[serde(default)]
41  pub verification_options: JwpVerificationOptions,
42}
43
44impl JptCredentialValidationOptions {
45  /// Constructor that sets all options to their defaults.
46  pub fn new() -> Self {
47    Self::default()
48  }
49
50  /// Declare that the credential is **not** considered valid if it expires before this [`Timestamp`].
51  /// Uses the current datetime during validation if not set.
52  pub fn earliest_expiry_date(mut self, timestamp: Timestamp) -> Self {
53    self.earliest_expiry_date = Some(timestamp);
54    self
55  }
56
57  /// Declare that the credential is **not** considered valid if it was issued later than this [`Timestamp`].
58  /// Uses the current datetime during validation if not set.
59  pub fn latest_issuance_date(mut self, timestamp: Timestamp) -> Self {
60    self.latest_issuance_date = Some(timestamp);
61    self
62  }
63
64  /// Sets the validation behaviour for [`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status).
65  pub fn status_check(mut self, status_check: crate::validator::StatusCheck) -> Self {
66    self.status = status_check;
67    self
68  }
69
70  /// Declares how credential subjects must relate to the presentation holder during validation.
71  ///
72  /// <https://www.w3.org/TR/vc-data-model/#subject-holder-relationships>
73  pub fn subject_holder_relationship(
74    mut self,
75    holder: Url,
76    subject_holder_relationship: SubjectHolderRelationship,
77  ) -> Self {
78    self.subject_holder_relationship = Some((holder, subject_holder_relationship));
79    self
80  }
81
82  /// Set options which affect the verification of the JWP proof.
83  pub fn verification_options(mut self, options: JwpVerificationOptions) -> Self {
84    self.verification_options = options;
85    self
86  }
87}