identity_jose/jose/
traits.rs

1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::jwt::JwtHeader;
5
6/// An abstraction over different JOSE headers.
7pub trait JoseHeader {
8  /// Returns the header common to all [`JoseHeader`]s.
9  fn common(&self) -> &JwtHeader;
10
11  /// Returns `true` if the header has the given `claim`, `false` otherwise.
12  fn has_claim(&self, claim: &str) -> bool;
13}
14
15impl<'a, T: 'a> JoseHeader for &'a T
16where
17  T: JoseHeader,
18{
19  fn common(&self) -> &JwtHeader {
20    (**self).common()
21  }
22
23  fn has_claim(&self, claim: &str) -> bool {
24    (**self).has_claim(claim)
25  }
26}