identity_credential/credential/jwt.rs
1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use serde::Deserialize;
5use serde::Serialize;
6
7/// A wrapper around a JSON Web Token (JWK).
8#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
9pub struct Jwt(String);
10
11impl Jwt {
12 /// Creates a new `Jwt` from the given string.
13 pub fn new(jwt_string: String) -> Self {
14 Self(jwt_string)
15 }
16
17 /// Returns a reference of the JWT string.
18 pub fn as_str(&self) -> &str {
19 &self.0
20 }
21}
22
23impl From<String> for Jwt {
24 fn from(jwt: String) -> Self {
25 Self::new(jwt)
26 }
27}
28
29impl From<Jwt> for String {
30 fn from(jwt: Jwt) -> Self {
31 jwt.0
32 }
33}