ate_comms/
certificate_validation.rs

1use std::sync::RwLock;
2use once_cell::sync::Lazy;
3use ate_crypto::AteHash;
4
5pub static GLOBAL_CERTIFICATES: Lazy<RwLock<Vec<AteHash>>> =
6    Lazy::new(|| RwLock::new(Vec::new()));
7
8pub fn add_global_certificate(cert: &AteHash) {
9    GLOBAL_CERTIFICATES.write().unwrap().push(cert.clone());
10}
11
12pub fn get_global_certificates() -> Vec<AteHash> {
13    let mut ret = GLOBAL_CERTIFICATES.read().unwrap().clone();
14    ret.push(AteHash::from_hex_string("f0a961c31f83c758ff0b669cc61b0f76").unwrap());
15    ret
16}
17
18#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
19pub enum CertificateValidation {
20    DenyAll,
21    AllowAll,
22    AllowedCertificates(Vec<AteHash>),
23}
24
25impl CertificateValidation {
26    pub fn validate(&self, cert: &AteHash) -> bool {
27        match self {
28            CertificateValidation::DenyAll => false,
29            CertificateValidation::AllowAll => true,
30            CertificateValidation::AllowedCertificates(a) => a.contains(cert),
31        }
32    }
33}