identity_credential/validator/
options.rs

1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use serde::Deserialize;
5use serde::Serialize;
6
7/// Controls validation behaviour when checking whether or not a credential has been revoked by its
8/// [`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status).
9#[derive(Debug, Clone, Copy, PartialEq, Eq, serde_repr::Serialize_repr, serde_repr::Deserialize_repr)]
10#[repr(u8)]
11pub enum StatusCheck {
12  /// Validate the status if supported, reject any unsupported
13  /// [`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status) types.
14  ///
15  /// Only `RevocationBitmap2022` is currently supported.
16  ///
17  /// This is the default.
18  Strict = 0,
19  /// Validate the status if supported, skip any unsupported
20  /// [`credentialStatus`](https://www.w3.org/TR/vc-data-model/#status) types.
21  SkipUnsupported = 1,
22  /// Skip all status checks.
23  SkipAll = 2,
24}
25
26impl Default for StatusCheck {
27  fn default() -> Self {
28    Self::Strict
29  }
30}
31
32/// Declares how credential subjects must relate to the presentation holder during validation.
33///
34/// See also the [Subject-Holder Relationship](https://www.w3.org/TR/vc-data-model/#subject-holder-relationships) section of the specification.
35// Need to use serde_repr to make this work with duck typed interfaces in the Wasm bindings.
36#[derive(Debug, Clone, Copy, serde_repr::Serialize_repr, serde_repr::Deserialize_repr)]
37#[repr(u8)]
38pub enum SubjectHolderRelationship {
39  /// The holder must always match the subject on all credentials, regardless of their [`nonTransferable`](https://www.w3.org/TR/vc-data-model/#nontransferable-property) property.
40  /// This is the variant returned by [Self::default](Self::default()) and the default used in
41  /// [`crate::validator::JwtPresentationValidationOptions`].
42  AlwaysSubject = 0,
43  /// The holder must match the subject only for credentials where the [`nonTransferable`](https://www.w3.org/TR/vc-data-model/#nontransferable-property) property is `true`.
44  SubjectOnNonTransferable = 1,
45  /// Declares that the subject is not required to have any kind of relationship to the holder.
46  Any = 2,
47}
48
49impl Default for SubjectHolderRelationship {
50  fn default() -> Self {
51    Self::AlwaysSubject
52  }
53}
54
55/// Declares when validation should return if an error occurs.
56#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
57pub enum FailFast {
58  /// Return all errors that occur during validation.
59  AllErrors,
60  /// Return after the first error occurs.
61  FirstError,
62}