identity_document/verifiable/
jws_verification_options.rs

1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use identity_did::DIDUrl;
5use identity_verification::MethodScope;
6
7/// Holds additional options for verifying a JWS with
8/// [`CoreDocument::verify_jws`](crate::document::CoreDocument::verify_jws()).
9#[non_exhaustive]
10#[derive(Default, Debug, serde::Serialize, serde::Deserialize, Clone)]
11#[serde(rename_all = "camelCase")]
12pub struct JwsVerificationOptions {
13  /// Verify that the nonce set in the protected header matches this value.
14  ///
15  /// [More Info](https://tools.ietf.org/html/rfc8555#section-6.5.2)
16  pub nonce: Option<String>,
17  /// Verify the signing verification method relation matches this.
18  pub method_scope: Option<MethodScope>,
19  /// The DID URl of the method, whose JWK should be used to verify the JWS.
20  /// If unset, the `kid` of the JWS is used as the DID Url.
21  pub method_id: Option<DIDUrl>,
22}
23
24impl JwsVerificationOptions {
25  /// Creates a new [`JwsVerificationOptions`].
26  pub fn new() -> Self {
27    Self::default()
28  }
29
30  /// Set the expected value for the `nonce` parameter of the protected header.
31  pub fn nonce(mut self, value: impl Into<String>) -> Self {
32    self.nonce = Some(value.into());
33    self
34  }
35
36  /// Set the scope of the verification methods that may be used to verify the given JWS.
37  pub fn method_scope(mut self, value: MethodScope) -> Self {
38    self.method_scope = Some(value);
39    self
40  }
41
42  /// The DID URl of the method, whose JWK should be used to verify the JWS.
43  pub fn method_id(mut self, value: DIDUrl) -> Self {
44    self.method_id = Some(value);
45    self
46  }
47}