Skip to main content

openvpn_mgmt_codec/
auth.rs

1use std::fmt;
2
3/// Authentication credential type. OpenVPN identifies credential requests
4/// by a quoted type string — usually `"Auth"` or `"Private Key"`, but
5/// plugins can define custom types.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum AuthType {
8    /// Standard `--auth-user-pass` credentials. Wire: `"Auth"`.
9    Auth,
10
11    /// Private key passphrase (encrypted key file). Wire: `"Private Key"`.
12    PrivateKey,
13
14    /// HTTP proxy credentials. Wire: `"HTTP Proxy"`.
15    HttpProxy,
16
17    /// SOCKS proxy credentials. Wire: `"SOCKS Proxy"`.
18    SocksProxy,
19
20    /// Plugin-defined or otherwise unrecognized auth type.
21    Custom(String),
22}
23
24impl fmt::Display for AuthType {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        match self {
27            Self::Auth => f.write_str("Auth"),
28            Self::PrivateKey => f.write_str("Private Key"),
29            Self::HttpProxy => f.write_str("HTTP Proxy"),
30            Self::SocksProxy => f.write_str("SOCKS Proxy"),
31            Self::Custom(s) => f.write_str(s),
32        }
33    }
34}
35
36/// Controls how OpenVPN retries after authentication failure.
37#[derive(Debug, Clone, Copy, PartialEq, Eq)]
38pub enum AuthRetryMode {
39    /// Don't retry — exit on auth failure.
40    None,
41
42    /// Retry, re-prompting for credentials.
43    Interact,
44
45    /// Retry without re-prompting.
46    NoInteract,
47}
48
49impl fmt::Display for AuthRetryMode {
50    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51        match self {
52            Self::None => f.write_str("none"),
53            Self::Interact => f.write_str("interact"),
54            Self::NoInteract => f.write_str("nointeract"),
55        }
56    }
57}