Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Commit db3344c

Browse files
committed
feat: impl TryFrom<AttributeTypeAndValue> for SessionId
1 parent 54f81be commit db3344c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/certs/mod.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ use der::asn1::BitString;
99
use der::pem::LineEnding;
1010
use der::{Decode, DecodePem, Encode, EncodePem};
1111
use spki::{AlgorithmIdentifierOwned, SubjectPublicKeyInfoOwned};
12+
use x509_cert::attr::AttributeTypeAndValue;
1213
use x509_cert::name::{Name, RdnSequence};
1314

1415
use crate::errors::CertificateConversionError;
1516
use crate::types::der::asn1::Ia5String;
16-
use crate::{Constrained, ConstraintError, OID_RDN_DOMAIN_COMPONENT};
17+
use crate::{Constrained, ConstraintError, OID_RDN_DOMAIN_COMPONENT, OID_RDN_UNIQUE_IDENTIFIER};
1718

1819
/// Additional capabilities ([x509_cert::ext::Extensions] or [x509_cert::attr::Attributes], depending
1920
/// on the context) of X.509 certificates.
@@ -90,6 +91,25 @@ impl TryFrom<Ia5String> for SessionId {
9091
}
9192
}
9293

94+
impl TryFrom<AttributeTypeAndValue> for SessionId {
95+
type Error = ConstraintError;
96+
97+
fn try_from(value: AttributeTypeAndValue) -> Result<Self, Self::Error> {
98+
if value.oid != OID_RDN_UNIQUE_IDENTIFIER {
99+
return Err(ConstraintError::Malformed(Some(format!(
100+
"Expected OID for uniqueIdentifier {OID_RDN_UNIQUE_IDENTIFIER}, found OID {}",
101+
value.oid
102+
))));
103+
}
104+
let ia5string = Ia5String::new(value.value.value()).map_err(|e| {
105+
ConstraintError::Malformed(Some(format!(
106+
"Value found in uniqueIdentifier is not a valid Ia5String: {e}"
107+
)))
108+
})?;
109+
Self::try_from(ia5string)
110+
}
111+
}
112+
93113
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
94114
/// Whether something is intended for an actor or a home server.
95115
#[allow(missing_docs)]

0 commit comments

Comments
 (0)