|
| 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