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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
// Copyright © 2022-2023 Mini Functions. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
//!
//! # A Rust library for accessing and manipulating claims of a JSON Web Token (JWT)
//!
//! [](https://minifunctions.com)
//!
//! <center>
//!
//! [](https://www.rust-lang.org)
//! [](https://crates.io/crates/mini-functions)
//! [](https://lib.rs/crates/mini-functions)
//! [](https://github.com/sebastienrousseau/mini-functions/tree/main/claims)
//! [](http://opensource.org/licenses/MIT)
//!
//! </center>
//!
//! ## Overview
//!
//! The Claims library holds JSON Web Token (JWT) claims. It provides an
//! RFC7519 compliant implementation of JSON Web Tokens (JWT) and JSON
//! Web Signature (JWS) for Rust.
//!
//! The [**`Claims`**](./struct.Claims.html) type is provided to hold
//! the claims of a JWT. The claims are stored in a `HashMap` and can be
//! accessed using the `get_claim`, `set_claim`, `remove_claim`, and
//! `has_claim` methods.
//!
//! ## Features
//!
//! The following table lists the optional reserved claims that are
//! supported:
//!
//! | Claim | Description |
//! | --- | --- |
//! | `aud` (Audience) | Identifies the recipients that the JWT is intended for. |
//! | `custom` (Custom) | Custom claims are used to share information between parties that agree on using them and are neither registered or public claims. |
//! | `did` (Decentralized Identifier) | A string value that uniquely identifies a subject. |
//! | `exp` (Expiration Time) | Identifies the expiration time on or after which the JWT MUST NOT be accepted for processing. |
//! | `iat` (Issued At) | Identifies the time at which the JWT was issued. |
//! | `iss` (Issuer) | Identifies the principal that issued the JWT. |
//! | `jti` (JWT ID) | Provides a unique identifier for the JWT. |
//! | `nbf` (Not Before) | Identifies the time before which the JWT MUST NOT be accepted for processing. |
//! | `sub` (Subject) | Identifies the principal that is the subject of the JWT. |
//! | `vc` (Verifiable Credential) | A Credential that is tamper-evident and has authorship that can be cryptographically verified. |
//! | `vp` (Verifiable Presentation) | A Presentation that is tamper-evident and has authorship that can be cryptographically verified. |
//!
//! ## Usage
//!
//! - [`serde`][]: Enable serialization/deserialization via serde
//!
//! ## Examples
//!
//! ```rust
//! use self::cclm::Claims;
//! use std::collections::HashMap;
//!
//! // Create a new instance of Claims
//! let mut claims = Claims::new();
//!
//! // Set a claim
//! claims.set_claim("name", "John Doe");
//!
//! // Get a claim
//! let name = claims.get_claim("name").unwrap(); // returns "John Doe"
//!
//! // Remove a claim
//! claims.remove_claim("name");
//!
//! // Clear all claims
//! claims.clear_claims();
//!
//! // Has a claim
//! let has_claim = claims.has_claim("name"); // returns false
//!
//! // Get the number of claims
//! let len = claims.len(); // returns 0
//!
//! // Is the claims empty?
//! let is_empty = claims.is_empty(); // returns true
//!
//! // Get the claims as a HashMap
//! let claims_map: &HashMap<String, String> = claims.get_claims();
//!
//! ```
//!
//! ## Links
//! * [RFC 7519](https://tools.ietf.org/html/rfc7519)
//! * [JSON Web Token (JWT)](https://jwt.io/)
//!
//!
//! [`serde`]: https://github.com/serde-rs/serde
//!
extern crate serde;
use ;
use HashMap;
/// The Claims struct holds the claims of a JSON Web Token (JWT).
///
/// A JWT is a compact, URL-safe means of representing claims to be
/// transferred between two parties. It consists of a header, a payload,
/// and a signature. The payload is where the claims are stored.
///
/// The claims in a JWT are encoded as a JSON object and can be used to
/// convey information such as the identity of an end user, the
/// expiration time of the token, and more.
///
/// The Claims struct provides a convenient way to manipulate the claims
/// of a JWT in Rust. It stores the claims as a HashMap<String, String>,
/// allowing for fast and efficient access to each claim.
/// Implement the `Display` trait for `Claims`.
/// Implement the `Default` trait for `Claims`.