use crate::constants::{
data_encryption_algorithm, digest_algorithm, key_encryption_algorithm, name_id_format,
signature_algorithm, transform_algorithm,
};
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub enum SignatureAlgorithm {
#[default]
RsaSha256,
RsaSha384,
RsaSha512,
Custom(String),
}
impl SignatureAlgorithm {
pub fn as_uri(&self) -> &str {
match self {
Self::RsaSha256 => signature_algorithm::RSA_SHA256,
Self::RsaSha384 => signature_algorithm::RSA_SHA384,
Self::RsaSha512 => signature_algorithm::RSA_SHA512,
Self::Custom(uri) => uri.as_str(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DigestAlgorithm {
Sha1ForCompatibility,
#[deprecated(note = "use DigestAlgorithm::Sha1ForCompatibility")]
Sha1,
Sha256,
Sha384,
Sha512,
Custom(String),
}
impl DigestAlgorithm {
#[expect(
deprecated,
reason = "deprecated algorithm aliases remain mapped for compatibility"
)]
pub fn as_uri(&self) -> &str {
match self {
Self::Sha1ForCompatibility | Self::Sha1 => digest_algorithm::SHA1,
Self::Sha256 => digest_algorithm::SHA256,
Self::Sha384 => digest_algorithm::SHA384,
Self::Sha512 => digest_algorithm::SHA512,
Self::Custom(uri) => uri.as_str(),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub enum DataEncryptionAlgorithm {
Aes128,
#[default]
Aes256,
TripleDesForCompatibility,
#[deprecated(note = "use DataEncryptionAlgorithm::TripleDesForCompatibility")]
TripleDes,
Aes128Gcm,
Custom(String),
}
impl DataEncryptionAlgorithm {
#[expect(
deprecated,
reason = "deprecated algorithm aliases remain mapped for compatibility"
)]
pub fn as_uri(&self) -> &str {
match self {
Self::Aes128 => data_encryption_algorithm::AES_128,
Self::Aes256 => data_encryption_algorithm::AES_256,
Self::TripleDesForCompatibility | Self::TripleDes => {
data_encryption_algorithm::TRIPLE_DES
}
Self::Aes128Gcm => data_encryption_algorithm::AES_128_GCM,
Self::Custom(uri) => uri.as_str(),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub enum KeyEncryptionAlgorithm {
#[default]
RsaOaepMgf1p,
Rsa15ForCompatibility,
#[deprecated(note = "use KeyEncryptionAlgorithm::Rsa15ForCompatibility")]
Rsa15,
Custom(String),
}
impl KeyEncryptionAlgorithm {
#[expect(
deprecated,
reason = "deprecated algorithm aliases remain mapped for compatibility"
)]
pub fn as_uri(&self) -> &str {
match self {
Self::RsaOaepMgf1p => key_encryption_algorithm::RSA_OAEP_MGF1P,
Self::Rsa15ForCompatibility | Self::Rsa15 => key_encryption_algorithm::RSA_1_5,
Self::Custom(uri) => uri.as_str(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TransformAlgorithm {
EnvelopedSignature,
ExclusiveCanonicalization,
Custom(String),
}
impl TransformAlgorithm {
pub fn as_uri(&self) -> &str {
match self {
Self::EnvelopedSignature => transform_algorithm::ENVELOPED_SIGNATURE,
Self::ExclusiveCanonicalization => transform_algorithm::EXC_C14N,
Self::Custom(uri) => uri.as_str(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NameIdFormat {
EmailAddress,
Persistent,
Transient,
Entity,
Unspecified,
Kerberos,
WindowsDomainQualifiedName,
X509SubjectName,
Custom(String),
}
impl NameIdFormat {
pub fn as_uri(&self) -> &str {
match self {
Self::EmailAddress => name_id_format::EMAIL_ADDRESS,
Self::Persistent => name_id_format::PERSISTENT,
Self::Transient => name_id_format::TRANSIENT,
Self::Entity => name_id_format::ENTITY,
Self::Unspecified => name_id_format::UNSPECIFIED,
Self::Kerberos => name_id_format::KERBEROS,
Self::WindowsDomainQualifiedName => name_id_format::WINDOWS_DOMAIN_QUALIFIED_NAME,
Self::X509SubjectName => name_id_format::X509_SUBJECT_NAME,
Self::Custom(uri) => uri.as_str(),
}
}
}
pub(super) fn name_id_format_uris(formats: &[NameIdFormat]) -> Vec<String> {
formats
.iter()
.map(|format| format.as_uri().to_string())
.collect()
}
pub(super) fn transform_algorithm_uris(algorithms: &[TransformAlgorithm]) -> Vec<String> {
algorithms
.iter()
.map(|algorithm| algorithm.as_uri().to_string())
.collect()
}