pubhubs/servers/
constellation.rs1use std::ops::Deref;
4
5use sha2::digest::Digest;
6
7use crate::api;
8use crate::common::elgamal;
9use crate::id;
10use crate::phcrypto;
11use crate::servers;
12
13#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
25pub struct Constellation {
26 pub id: id::Id,
28
29 pub created_at: api::NumericDate,
33
34 #[serde(flatten)]
35 pub inner: Inner,
36}
37
38impl Deref for Constellation {
39 type Target = Inner;
40
41 fn deref(&self) -> &Inner {
42 &self.inner
43 }
44}
45#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
54pub struct Inner {
55 pub transcryptor_url: url::Url,
56 pub transcryptor_jwt_key: api::VerifyingKey,
57 pub transcryptor_enc_key: elgamal::PublicKey,
58 pub transcryptor_master_enc_key_part: elgamal::PublicKey,
60
61 pub phc_url: url::Url,
62 pub phc_jwt_key: api::VerifyingKey,
63 pub phc_enc_key: elgamal::PublicKey,
64
65 pub auths_url: url::Url,
66 pub auths_jwt_key: api::VerifyingKey,
67 pub auths_enc_key: elgamal::PublicKey,
68
69 pub master_enc_key: elgamal::PublicKey,
71
72 pub global_client_url: url::Url,
73
74 pub ph_version: Option<String>,
76}
77
78impl Inner {
79 pub fn url(&self, name: servers::Name) -> &url::Url {
81 match name {
82 servers::Name::PubhubsCentral => &self.phc_url,
83 servers::Name::Transcryptor => &self.transcryptor_url,
84 servers::Name::AuthenticationServer => &self.auths_url,
85 }
86 }
87
88 pub(crate) fn sha256(&self) -> sha2::Sha256 {
90 let Inner {
91 transcryptor_url,
92 transcryptor_jwt_key,
93 transcryptor_enc_key,
94 transcryptor_master_enc_key_part,
95
96 phc_url,
97 phc_jwt_key,
98 phc_enc_key,
99
100 auths_url,
101 auths_jwt_key,
102 auths_enc_key,
103
104 global_client_url,
105
106 master_enc_key,
107 ph_version,
108 } = self;
109
110 sha2::Sha256::new()
115 .chain_update(transcryptor_url.as_str())
116 .chain_update(**transcryptor_jwt_key)
117 .chain_update(transcryptor_enc_key)
118 .chain_update(transcryptor_master_enc_key_part)
119 .chain_update(phc_url.as_str())
120 .chain_update(**phc_jwt_key)
121 .chain_update(phc_enc_key)
122 .chain_update(auths_url.as_str())
123 .chain_update(**auths_jwt_key)
124 .chain_update(auths_enc_key)
125 .chain_update(master_enc_key)
126 .chain_update(global_client_url.as_str())
127 .chain_update(ph_version.as_ref().map(String::as_str).unwrap_or("n/a"))
128 }
129
130 pub fn derive_id(&self) -> id::Id {
131 phcrypto::constellation_id(self)
132 }
133}
134
135#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
137#[serde(untagged)]
138pub enum ConstellationOrId {
139 Constellation(Box<Constellation>),
140 Id { id: id::Id },
141}
142
143impl ConstellationOrId {
144 pub fn constellation(&self) -> Option<&Constellation> {
146 if let Self::Constellation(c) = self {
147 return Some(c);
148 }
149 None
150 }
151
152 pub fn into_constellation(self) -> Option<Constellation> {
154 if let Self::Constellation(c) = self {
155 return Some(*c);
156 }
157 None
158 }
159
160 pub fn id(&self) -> &id::Id {
162 match self {
163 Self::Constellation(c) => &c.id,
164 Self::Id { id } => id,
165 }
166 }
167}