(&self, cert_der: &[u8])
| 296 | |
| 297 | impl CertValidator for AppIdValidator { |
| 298 | fn validate(&self, cert_der: &[u8]) -> Result<(), String> { |
| 299 | use ra_tls::traits::CertExt; |
| 300 | |
| 301 | let (_, cert) = x509_parser::parse_x509_certificate(cert_der) |
| 302 | .map_err(|e| format!("failed to parse certificate: {e}"))?; |
| 303 | |
| 304 | let peer_app_id = cert |
| 305 | .get_app_id() |
| 306 | .map_err(|e| format!("failed to get app_id: {e}"))?; |
| 307 | |
| 308 | let Some(peer_app_id) = peer_app_id else { |
| 309 | return Err("peer certificate does not contain app_id".into()); |
| 310 | }; |
| 311 | |
| 312 | if peer_app_id != self.expected_app_id { |
| 313 | return Err(format!( |
| 314 | "app_id mismatch: expected {}, got {}", |
| 315 | hex::encode(&self.expected_app_id), |
| 316 | hex::encode(&peer_app_id) |
| 317 | )); |
| 318 | } |
| 319 | |
| 320 | Ok(()) |
| 321 | } |
| 322 | } |
no test coverage detected