json_web_tolkien/algorithm.rs
1use serde::{Deserialize, Serialize};
2
3/// JWA supported algorithms.
4/// See [IETF RFC 7518](https://datatracker.ietf.org/doc/html/rfc7518#section-3.1)
5#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
6pub enum Algorithm {
7 /// HMAC using SHA-256
8 HS256,
9 /// HMAC using SHA-384
10 HS384,
11 /// HMAC using SHA-512
12 HS512,
13 /// RSASSA-PKCS1-v1_5 using SHA-256
14 RS256,
15 /// RSASSA-PKCS1-v1_5 using SHA-384
16 RS384,
17 /// RSASSA-PKCS1-v1_5 using SHA-512
18 RS512,
19 /// ECDSA using P-256 and SHA-256
20 ES256,
21 /// ECDSA using P-384 and SHA-384
22 ES384,
23 /// ECDSA using P-512 and SHA-512
24 ES512,
25 /// RSASSA-PSS and MFG1 using SHA-256
26 PS256,
27 /// RSASSA-PSS and MFG1 using SHA-384
28 PS384,
29 /// RSASSA-PSS and MFG1 using SHA-512
30 PS512,
31 /// No digital signature or MAC
32 None,
33}
34#[allow(clippy::len_without_is_empty)]
35impl Algorithm {
36 pub fn len(&self) -> usize {
37 match self {
38 Self::HS256 | Self::RS256 | Self::ES256 | Self::PS256 => 32,
39 Self::HS384 | Self::RS384 | Self::ES384 | Self::PS384 => 48,
40 Self::HS512 | Self::RS512 | Self::ES512 | Self::PS512 => 64,
41 _ => 0,
42 }
43 }
44}