@@ -9,11 +9,12 @@ use der::asn1::BitString;
99use der:: pem:: LineEnding ;
1010use der:: { Decode , DecodePem , Encode , EncodePem } ;
1111use spki:: { AlgorithmIdentifierOwned , SubjectPublicKeyInfoOwned } ;
12+ use x509_cert:: attr:: AttributeTypeAndValue ;
1213use x509_cert:: name:: { Name , RdnSequence } ;
1314
1415use crate :: errors:: CertificateConversionError ;
1516use 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