identity_jose/jws/
recipient.rs

1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::jws::JwsHeader;
5
6/// The recipient of a JWS.
7///
8/// The contained headers determine the specifics of the signature for that recipient,
9/// such as what algorithm (`alg`) or key (`kid`) will be or was used to create the signature.
10#[derive(Clone, Copy)]
11pub struct Recipient<'a> {
12  /// The integrity-protected JOSE header.
13  pub protected: Option<&'a JwsHeader>,
14  /// The non integrity-protected JOSE header.
15  pub unprotected: Option<&'a JwsHeader>,
16}
17
18impl Default for Recipient<'_> {
19  fn default() -> Self {
20    Self::new()
21  }
22}
23
24impl<'a> Recipient<'a> {
25  /// Creates a new recipient with no header set.
26  pub fn new() -> Self {
27    Self {
28      protected: None,
29      unprotected: None,
30    }
31  }
32
33  /// Set the integrity-protected JOSE header.
34  pub fn protected(mut self, value: &'a JwsHeader) -> Self {
35    self.protected = Some(value);
36    self
37  }
38
39  /// Set the non integrity-protected JOSE header.
40  pub fn unprotected(mut self, value: &'a JwsHeader) -> Self {
41    self.unprotected = Some(value);
42    self
43  }
44}