identity_jose/jose/
traits.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright 2020-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use crate::jwt::JwtHeader;

/// An abstraction over different JOSE headers.
pub trait JoseHeader {
  /// Returns the header common to all [`JoseHeader`]s.
  fn common(&self) -> &JwtHeader;

  /// Returns `true` if the header has the given `claim`, `false` otherwise.
  fn has_claim(&self, claim: &str) -> bool;
}

impl<'a, T: 'a> JoseHeader for &'a T
where
  T: JoseHeader,
{
  fn common(&self) -> &JwtHeader {
    (**self).common()
  }

  fn has_claim(&self, claim: &str) -> bool {
    (**self).has_claim(claim)
  }
}