1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
use rpki::crypto::KeyIdentifier;
use rpki::uri;

use crate::commons::api::Handle;
use crate::commons::remote::id::IdCert;

//------------ Client ------------------------------------------------------

/// Represents a known client that can be proxied.
#[derive(Debug, Clone, Deserialize, Eq, PartialEq, Serialize)]
pub struct ClientAuth {
    // Certificate used by the client
    cert: IdCert,
}

impl ClientAuth {
    pub fn new(cert: IdCert) -> Self {
        ClientAuth { cert }
    }
    pub fn cert(&self) -> &IdCert {
        &self.cert
    }
    pub fn set_cert(&mut self, cert: IdCert) {
        self.cert = cert;
    }
}

//------------ ClientInfo ---------------------------------------------------

#[derive(Debug, Clone, Deserialize, Eq, PartialEq, Serialize)]
pub struct ClientInfo {
    handle: Handle,
    auth: ClientAuth,
}

impl ClientInfo {
    pub fn new(handle: Handle, auth: ClientAuth) -> Self {
        ClientInfo { handle, auth }
    }
    pub fn unwrap(self) -> (Handle, ClientAuth) {
        (self.handle, self.auth)
    }
    pub fn handle(&self) -> &Handle {
        &self.handle
    }
    pub fn auth(&self) -> &ClientAuth {
        &self.auth
    }
}

//------------ CmsClientInfo -----------------------------------------------

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct CmsClientInfo {
    handle: Handle,
    server_cert: IdCert,
    key_id: KeyIdentifier,
    publication_uri: uri::Https,
}

impl CmsClientInfo {
    pub fn new(
        handle: Handle,
        cert: IdCert,
        key_id: KeyIdentifier,
        publication_uri: uri::Https,
    ) -> Self {
        CmsClientInfo {
            handle,
            server_cert: cert,
            key_id,
            publication_uri,
        }
    }

    pub fn handle(&self) -> &Handle {
        &self.handle
    }
    pub fn set_handle(&mut self, handle: Handle) {
        self.handle = handle;
    }
    pub fn server_cert(&self) -> &IdCert {
        &self.server_cert
    }
    pub fn set_server_cert(&mut self, cert: IdCert) {
        self.server_cert = cert;
    }
    pub fn key_id(&self) -> KeyIdentifier {
        self.key_id
    }
    pub fn set_key_id(&mut self, key_id: KeyIdentifier) {
        self.key_id = key_id;
    }
    pub fn publication_uri(&self) -> &uri::Https {
        &self.publication_uri
    }
    pub fn set_publication_uri(&mut self, uri: uri::Https) {
        self.publication_uri = uri;
    }
}