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
use std::fmt::{self, Display};

/// Default timeouts for reading and writing (5 seconds)
pub const DEFAULT_TIMEOUT_MILLIS: u64 = 5000;

/// Configuration options for the HTTP (i.e. `yubihsm-connector`) adapter
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct HttpConfig {
    /// Address of `yubihsm-connector` (IP address or DNS name)
    pub addr: String,

    /// Port `yubihsm-connector` process is listening on
    pub port: u16,

    /// Timeout for connecting, reading, and writing in milliseconds
    pub timeout_ms: u64,
}

impl Default for HttpConfig {
    fn default() -> Self {
        Self {
            // Default `yubihsm-connector` address
            addr: "127.0.0.1".to_owned(),

            // Default `yubihsm-connector` port
            port: 12345,

            // 5 seconds
            timeout_ms: DEFAULT_TIMEOUT_MILLIS,
        }
    }
}

impl Display for HttpConfig {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        // TODO: HTTPS support
        write!(f, "http://{}:{}", self.addr, self.port)
    }
}