1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum Algorithm {
8 Ed25519,
10 X25519,
12 P256,
14 P384,
16 P521,
18 Secp256k1,
20 MlDsa44,
22 MlDsa65,
24 MlDsa87,
26 SlhDsaSha2_128s,
28 MlKem512,
30 MlKem768,
32 MlKem1024,
34 XWing768,
36}
37
38impl Algorithm {
39 pub fn as_str(self) -> &'static str {
42 match self {
43 Algorithm::Ed25519 => "Ed25519",
44 Algorithm::X25519 => "X25519",
45 Algorithm::P256 => "P-256",
46 Algorithm::P384 => "P-384",
47 Algorithm::P521 => "P-521",
48 Algorithm::Secp256k1 => "secp256k1",
49 Algorithm::MlDsa44 => "ML-DSA-44",
50 Algorithm::MlDsa65 => "ML-DSA-65",
51 Algorithm::MlDsa87 => "ML-DSA-87",
52 Algorithm::SlhDsaSha2_128s => "SLH-DSA-SHA2-128s",
53 Algorithm::MlKem512 => "ML-KEM-512",
54 Algorithm::MlKem768 => "ML-KEM-768",
55 Algorithm::MlKem1024 => "ML-KEM-1024",
56 Algorithm::XWing768 => "X-Wing-768",
57 }
58 }
59
60 pub fn is_signature(self) -> bool {
62 matches!(
63 self,
64 Algorithm::Ed25519
65 | Algorithm::P256
66 | Algorithm::P384
67 | Algorithm::P521
68 | Algorithm::Secp256k1
69 | Algorithm::MlDsa44
70 | Algorithm::MlDsa65
71 | Algorithm::MlDsa87
72 | Algorithm::SlhDsaSha2_128s
73 )
74 }
75
76 pub fn is_key_agreement(self) -> bool {
78 matches!(
79 self,
80 Algorithm::X25519
81 | Algorithm::P256
82 | Algorithm::P384
83 | Algorithm::P521
84 | Algorithm::MlKem512
85 | Algorithm::MlKem768
86 | Algorithm::MlKem1024
87 | Algorithm::XWing768
88 )
89 }
90}
91
92impl core::fmt::Display for Algorithm {
93 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
94 write!(f, "{}", self.as_str())
95 }
96}
97
98#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
100pub enum AeadAlgorithm {
101 Aes128Gcm,
103 Aes192Gcm,
105 Aes256Gcm,
107 Aes256GcmSiv,
109 ChaCha20Poly1305,
111 XChaCha20Poly1305,
113}
114
115impl AeadAlgorithm {
116 pub fn as_str(self) -> &'static str {
118 match self {
119 AeadAlgorithm::Aes128Gcm => "AES-128-GCM",
120 AeadAlgorithm::Aes192Gcm => "AES-192-GCM",
121 AeadAlgorithm::Aes256Gcm => "AES-256-GCM",
122 AeadAlgorithm::Aes256GcmSiv => "AES-256-GCM-SIV",
123 AeadAlgorithm::ChaCha20Poly1305 => "ChaCha20-Poly1305",
124 AeadAlgorithm::XChaCha20Poly1305 => "XChaCha20-Poly1305",
125 }
126 }
127}
128
129impl core::fmt::Display for AeadAlgorithm {
130 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
131 write!(f, "{}", self.as_str())
132 }
133}
134
135#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
137pub enum HashAlgorithm {
138 Sha2_256,
140 Sha2_384,
142 Sha2_512,
144 Sha3_224,
146 Sha3_256,
148 Sha3_384,
150 Sha3_512,
152}
153
154impl HashAlgorithm {
155 pub fn as_str(self) -> &'static str {
157 match self {
158 HashAlgorithm::Sha2_256 => "SHA2-256",
159 HashAlgorithm::Sha2_384 => "SHA2-384",
160 HashAlgorithm::Sha2_512 => "SHA2-512",
161 HashAlgorithm::Sha3_224 => "SHA3-224",
162 HashAlgorithm::Sha3_256 => "SHA3-256",
163 HashAlgorithm::Sha3_384 => "SHA3-384",
164 HashAlgorithm::Sha3_512 => "SHA3-512",
165 }
166 }
167}
168
169impl core::fmt::Display for HashAlgorithm {
170 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
171 write!(f, "{}", self.as_str())
172 }
173}
174
175#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
177pub enum MacAlgorithm {
178 HmacSha256,
180 HmacSha384,
182 HmacSha512,
184}
185
186impl MacAlgorithm {
187 pub fn as_str(self) -> &'static str {
189 match self {
190 MacAlgorithm::HmacSha256 => "HMAC-SHA-256",
191 MacAlgorithm::HmacSha384 => "HMAC-SHA-384",
192 MacAlgorithm::HmacSha512 => "HMAC-SHA-512",
193 }
194 }
195}
196
197impl core::fmt::Display for MacAlgorithm {
198 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
199 write!(f, "{}", self.as_str())
200 }
201}