1use crate::constants::{
2 data_encryption_algorithm, digest_algorithm, key_encryption_algorithm, name_id_format,
3 signature_algorithm, transform_algorithm,
4};
5
6#[derive(Debug, Clone, Default, PartialEq, Eq)]
11pub enum SignatureAlgorithm {
12 #[default]
14 RsaSha256,
15 RsaSha384,
17 RsaSha512,
19 Custom(String),
21}
22
23impl SignatureAlgorithm {
24 pub fn as_uri(&self) -> &str {
26 match self {
27 Self::RsaSha256 => signature_algorithm::RSA_SHA256,
28 Self::RsaSha384 => signature_algorithm::RSA_SHA384,
29 Self::RsaSha512 => signature_algorithm::RSA_SHA512,
30 Self::Custom(uri) => uri.as_str(),
31 }
32 }
33}
34
35#[derive(Debug, Clone, PartialEq, Eq)]
40pub enum DigestAlgorithm {
41 Sha1ForCompatibility,
43 #[deprecated(note = "use DigestAlgorithm::Sha1ForCompatibility")]
45 Sha1,
46 Sha256,
48 Sha384,
50 Sha512,
52 Custom(String),
54}
55
56impl DigestAlgorithm {
57 #[expect(
59 deprecated,
60 reason = "deprecated algorithm aliases remain mapped for compatibility"
61 )]
62 pub fn as_uri(&self) -> &str {
63 match self {
64 Self::Sha1ForCompatibility | Self::Sha1 => digest_algorithm::SHA1,
65 Self::Sha256 => digest_algorithm::SHA256,
66 Self::Sha384 => digest_algorithm::SHA384,
67 Self::Sha512 => digest_algorithm::SHA512,
68 Self::Custom(uri) => uri.as_str(),
69 }
70 }
71}
72
73#[derive(Debug, Clone, Default, PartialEq, Eq)]
78pub enum DataEncryptionAlgorithm {
79 Aes128,
81 #[default]
83 Aes256,
84 TripleDesForCompatibility,
86 #[deprecated(note = "use DataEncryptionAlgorithm::TripleDesForCompatibility")]
88 TripleDes,
89 Aes128Gcm,
91 Custom(String),
93}
94
95impl DataEncryptionAlgorithm {
96 #[expect(
98 deprecated,
99 reason = "deprecated algorithm aliases remain mapped for compatibility"
100 )]
101 pub fn as_uri(&self) -> &str {
102 match self {
103 Self::Aes128 => data_encryption_algorithm::AES_128,
104 Self::Aes256 => data_encryption_algorithm::AES_256,
105 Self::TripleDesForCompatibility | Self::TripleDes => {
106 data_encryption_algorithm::TRIPLE_DES
107 }
108 Self::Aes128Gcm => data_encryption_algorithm::AES_128_GCM,
109 Self::Custom(uri) => uri.as_str(),
110 }
111 }
112}
113
114#[derive(Debug, Clone, Default, PartialEq, Eq)]
119pub enum KeyEncryptionAlgorithm {
120 #[default]
122 RsaOaepMgf1p,
123 Rsa15ForCompatibility,
125 #[deprecated(note = "use KeyEncryptionAlgorithm::Rsa15ForCompatibility")]
127 Rsa15,
128 Custom(String),
130}
131
132impl KeyEncryptionAlgorithm {
133 #[expect(
135 deprecated,
136 reason = "deprecated algorithm aliases remain mapped for compatibility"
137 )]
138 pub fn as_uri(&self) -> &str {
139 match self {
140 Self::RsaOaepMgf1p => key_encryption_algorithm::RSA_OAEP_MGF1P,
141 Self::Rsa15ForCompatibility | Self::Rsa15 => key_encryption_algorithm::RSA_1_5,
142 Self::Custom(uri) => uri.as_str(),
143 }
144 }
145}
146
147#[derive(Debug, Clone, PartialEq, Eq)]
152pub enum TransformAlgorithm {
153 EnvelopedSignature,
155 ExclusiveCanonicalization,
157 Custom(String),
159}
160
161impl TransformAlgorithm {
162 pub fn as_uri(&self) -> &str {
164 match self {
165 Self::EnvelopedSignature => transform_algorithm::ENVELOPED_SIGNATURE,
166 Self::ExclusiveCanonicalization => transform_algorithm::EXC_C14N,
167 Self::Custom(uri) => uri.as_str(),
168 }
169 }
170}
171
172#[derive(Debug, Clone, PartialEq, Eq)]
174pub enum NameIdFormat {
175 EmailAddress,
177 Persistent,
179 Transient,
181 Entity,
183 Unspecified,
185 Kerberos,
187 WindowsDomainQualifiedName,
189 X509SubjectName,
191 Custom(String),
193}
194
195impl NameIdFormat {
196 pub fn as_uri(&self) -> &str {
198 match self {
199 Self::EmailAddress => name_id_format::EMAIL_ADDRESS,
200 Self::Persistent => name_id_format::PERSISTENT,
201 Self::Transient => name_id_format::TRANSIENT,
202 Self::Entity => name_id_format::ENTITY,
203 Self::Unspecified => name_id_format::UNSPECIFIED,
204 Self::Kerberos => name_id_format::KERBEROS,
205 Self::WindowsDomainQualifiedName => name_id_format::WINDOWS_DOMAIN_QUALIFIED_NAME,
206 Self::X509SubjectName => name_id_format::X509_SUBJECT_NAME,
207 Self::Custom(uri) => uri.as_str(),
208 }
209 }
210}
211
212pub(super) fn name_id_format_uris(formats: &[NameIdFormat]) -> Vec<String> {
213 formats
214 .iter()
215 .map(|format| format.as_uri().to_string())
216 .collect()
217}
218
219pub(super) fn transform_algorithm_uris(algorithms: &[TransformAlgorithm]) -> Vec<String> {
220 algorithms
221 .iter()
222 .map(|algorithm| algorithm.as_uri().to_string())
223 .collect()
224}