Completely refactor project structure
parent: tbd commit: ae8ff44
1 | use ; |
2 | |
3 | use Error; |
4 | use Future; |
5 | use |
6 | , |
7 | , | Instance
8 | , | User
9 | ; |
10 | use ; |
11 | use |
12 | , |
13 | , |
14 | , | Sha256
15 | , | Verifier
16 | RsaPublicKey, |
17 | ; |
18 | use ; |
19 | use Value; |
20 | |
21 | use crate ConnectionState; |
22 | |
23 | ; |
24 | |
25 | |
26 | type Target = ; |
27 | |
28 | |
29 | &self.0 |
30 | |
31 | |
32 | |
33 | ; |
34 | |
35 | |
36 | |
37 | |
38 | Missing, |
39 | // #[error("{0}")] |
40 | // InstanceAuthentication(#[from] Error), |
41 | |
42 | InvalidToken, |
43 | |
44 | Other, |
45 | |
46 | |
47 | ; |
48 | |
49 | |
50 | |
51 | &self.0 |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | async ; |
58 | |
59 | |
60 | |
61 | |
62 | async |
63 | network_message: &NetworkMessage, |
64 | state: &ConnectionState, |
65 | |
66 | let message: = |
67 | map_err?; | from_slice .
68 | |
69 | let = message |
70 | .source |
71 | .iter |
72 | .filter_map |
73 | if let User = auth |
74 | Some |
75 | else |
76 | None |
77 | |
78 | |
79 | .next |
80 | .ok_or_else?; |
81 | |
82 | let authenticated_instance = |
83 | ?; | from_message .await
84 | |
85 | let public_key_raw = public_key .await?; |
86 | let verification_key = from_rsa_pem .unwrap; |
87 | |
88 | let data: = decode |
89 | auth_token.as_ref, |
90 | &verification_key, |
91 | & new, |
92 | |
93 | .unwrap; |
94 | |
95 | if data.claims.user != *auth_user |
96 | || data.claims.generated_for != *authenticated_instance.inner |
97 | |
98 | Err |
99 | else |
100 | Ok |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | |
107 | async |
108 | network_message: &NetworkMessage, |
109 | state: &ConnectionState, |
110 | |
111 | let message: = |
112 | map_err?; | from_slice .
113 | |
114 | let = message |
115 | .source |
116 | .iter |
117 | .filter_map |
118 | if let Instance |
119 | instance, |
120 | signature, |
121 | = auth |
122 | |
123 | Some |
124 | else |
125 | None |
126 | |
127 | |
128 | .next |
129 | // TODO: Instance authentication error |
130 | .ok_or_else?; |
131 | |
132 | let public_key = |
133 | let cached_keys = state.cached_keys.read .await; |
134 | |
135 | if let Some = cached_keys.get |
136 | key.clone |
137 | else |
138 | drop; |
139 | let mut cached_keys = state.cached_keys.write .await; |
140 | let key = public_key .await?; |
141 | let public_key = from_pkcs1_pem .unwrap; |
142 | cached_keys.insert; |
143 | public_key |
144 | |
145 | ; |
146 | |
147 | let verifying_key: = new; |
148 | |
149 | let message_json = to_vec .unwrap; |
150 | |
151 | verifying_key.verify |
152 | &message_json, |
153 | & try_from .unwrap, |
154 | ?; |
155 | |
156 | Ok |
157 | |
158 | |
159 | |
160 | |
161 | |
162 | |
163 | T: , |
164 | S: Send + Sync + 'static, |
165 | |
166 | async |
167 | Ok |
168 | |
169 | |
170 | |
171 | |
172 | |
173 | async ; |
174 | |
175 | |
176 | |
177 | |
178 | T: FnOnce(T1) -> F + Clone + Send + 'static, |
179 | F: + Send, |
180 | T1: + Send, |
181 | S: Send + Sync, |
182 | E: Error + Send + Sync + 'static, |
183 | |
184 | async |
185 | let value = T1 from_message .await?; |
186 | self .await.map_err |
187 | |
188 | |
189 | |
190 | |
191 | |
192 | |
193 | T: FnOnce(T1, T2) -> F + Clone + Send + 'static, |
194 | F: + Send, |
195 | T1: + Send, |
196 | T2: + Send, |
197 | S: Send + Sync, |
198 | E: Error + Send + Sync + 'static, |
199 | |
200 | async |
201 | let value = T1 from_message .await?; |
202 | let value_2 = T2 from_message .await?; |
203 | self .await.map_err |
204 | |
205 | |
206 | |
207 | |
208 | |
209 | |
210 | T: FnOnce(T1, T2, T3) -> F + Clone + Send + 'static, |
211 | F: + Send, |
212 | T1: + Send, |
213 | T2: + Send, |
214 | T3: + Send, |
215 | S: Send + Sync, |
216 | E: Error + Send + Sync + 'static, |
217 | |
218 | async |
219 | let value = T1 from_message .await?; |
220 | let value_2 = T2 from_message .await?; |
221 | let value_3 = T3 from_message .await?; |
222 | |
223 | self |
224 | .await |
225 | .map_err |
226 | |
227 | |
228 | |
229 | ; |
230 | |
231 | |
232 | |
233 | |
234 | T: Clone + Send + Sync, |
235 | |
236 | async |
237 | Ok |
238 | |
239 | |
240 | |
241 | // Temp |
242 | |
243 | |
244 | |
245 | T: DeserializeOwned + Send + Sync + Serialize, |
246 | S: Clone + Send + Sync, |
247 | |
248 | async |
249 | Ok |
250 | |
251 | |
252 | |
253 | ; |
254 | |
255 | async |
256 | let key = get |
257 | .await? |
258 | .text |
259 | .await?; |
260 | |
261 | Ok |
262 | |
263 |