11use std:: hash:: Hash ;
22
3- use x509_cert:: name:: RelativeDistinguishedName ;
3+ use x509_cert:: attr:: AttributeTypeAndValue ;
4+ use x509_cert:: name:: { Name , RelativeDistinguishedName } ;
45
56use crate :: certs:: SessionId ;
67use crate :: types:: { DomainName , FederationId } ;
8+ use crate :: {
9+ OID_RDN_COMMON_NAME , OID_RDN_DOMAIN_COMPONENT , OID_RDN_UID , OID_RDN_UNIQUE_IDENTIFIER ,
10+ } ;
711
812/// Higher-level abstraction of X.509 [distinguished names](https://ldap.com/ldap-dns-and-rdns/),
913/// providing easier access to inner values compared to using [x509_cert::name::Name] in a raw manner.
1014#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1115pub enum PolyprotoDistinguishedName {
12- /// A `pDN` with all necessary fields
16+ /// A `pDN` with all necessary fields for an actor.
1317 ActorDn ( ActorDN ) ,
18+ /// A `pDN` with all necessary fields for a home server.
1419 HomeServerDn ( HomeServerDN ) ,
1520}
1621
1722#[ derive( Debug , Clone , PartialEq , Eq ) ]
23+ /// A [PolyprotoDistinguishedName] with all necessary fields for an actor certificate.
24+ ///
25+ /// This struct is a higher-level abstraction of X.509 [distinguished names](https://ldap.com/ldap-dns-and-rdns/),
26+ /// providing easier access to inner values compared to using [x509_cert::name::Name] in a raw manner.
1827pub struct ActorDN {
1928 federation_id : FederationId ,
2029 domain_name : DomainName ,
@@ -34,6 +43,10 @@ impl Hash for ActorDN {
3443}
3544
3645#[ derive( Debug , Clone , PartialEq , Eq ) ]
46+ /// A [PolyprotoDistinguishedName] with all necessary fields for a home server certificate.
47+ ///
48+ /// This struct is a higher-level abstraction of X.509 [distinguished names](https://ldap.com/ldap-dns-and-rdns/),
49+ /// providing easier access to inner values compared to using [x509_cert::name::Name] in a raw manner.
3750pub struct HomeServerDN {
3851 domain_name : DomainName ,
3952 additional_fields : Vec < RelativeDistinguishedName > ,
@@ -47,3 +60,26 @@ impl Hash for HomeServerDN {
4760 . for_each ( |additional_field| additional_field. to_string ( ) . hash ( state) ) ;
4861 }
4962}
63+
64+ impl TryFrom < Name > for ActorDN {
65+ type Error = crate :: errors:: InvalidInput ;
66+
67+ fn try_from ( x509_distinguished_name : Name ) -> Result < Self , Self :: Error > {
68+ let federation_id: AttributeTypeAndValue ;
69+ let domain_name: AttributeTypeAndValue ;
70+ let session_id: AttributeTypeAndValue ;
71+ let additional_fields: AttributeTypeAndValue ;
72+ for relative_distinguished_name in x509_distinguished_name. 0 . into_iter ( ) {
73+ for attribute_value_and_item in relative_distinguished_name. 0 . iter ( ) {
74+ match attribute_value_and_item. oid {
75+ OID_RDN_COMMON_NAME => ( ) ,
76+ OID_RDN_UID => ( ) ,
77+ OID_RDN_UNIQUE_IDENTIFIER => ( ) ,
78+ OID_RDN_DOMAIN_COMPONENT => ( ) ,
79+ other => ( ) ,
80+ }
81+ }
82+ }
83+ todo ! ( )
84+ }
85+ }
0 commit comments