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

Commit d29b46b

Browse files
committed
feat(squashme): start working on pdn types
1 parent 087c7b3 commit d29b46b

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/types/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub mod encrypted_pkm;
1212
/// Module defining the [FederationId] type.
1313
#[cfg(feature = "types")]
1414
pub mod federation_id;
15+
/// Module defining the [PolyprotoDistinguishedName] type.
16+
pub mod pdn;
1517

1618
/// Module defining the [Service] type.
1719
#[cfg(feature = "types")]

src/types/pdn.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use std::hash::Hash;
2+
3+
use x509_cert::name::RelativeDistinguishedName;
4+
5+
use crate::certs::SessionId;
6+
use crate::types::{DomainName, FederationId};
7+
8+
/// Higher-level abstraction of X.509 [distinguished names](https://ldap.com/ldap-dns-and-rdns/),
9+
/// providing easier access to inner values compared to using [x509_cert::name::Name] in a raw manner.
10+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11+
pub enum PolyprotoDistinguishedName {
12+
/// A `pDN` with all necessary fields
13+
ActorDn(ActorDN),
14+
HomeServerDn(HomeServerDN),
15+
}
16+
17+
#[derive(Debug, Clone, PartialEq, Eq)]
18+
pub struct ActorDN {
19+
federation_id: FederationId,
20+
domain_name: DomainName,
21+
session_id: SessionId,
22+
additional_fields: Vec<RelativeDistinguishedName>,
23+
}
24+
25+
impl Hash for ActorDN {
26+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
27+
self.federation_id.hash(state);
28+
self.domain_name.hash(state);
29+
self.session_id.hash(state);
30+
self.additional_fields
31+
.iter()
32+
.for_each(|additional_field| additional_field.to_string().hash(state));
33+
}
34+
}
35+
36+
#[derive(Debug, Clone, PartialEq, Eq)]
37+
pub struct HomeServerDN {
38+
domain_name: DomainName,
39+
additional_fields: Vec<RelativeDistinguishedName>,
40+
}
41+
42+
impl Hash for HomeServerDN {
43+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
44+
self.domain_name.hash(state);
45+
self.additional_fields
46+
.iter()
47+
.for_each(|additional_field| additional_field.to_string().hash(state));
48+
}
49+
}

0 commit comments

Comments
 (0)