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
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Attribute {
/** Name of the SSL implementation in use. (Currently, only "OpenSSL" is implemented) */
Library,
/**
* SSL/TLS version in use. Common values are "TLSv1", "TLSv1.1" and "TLSv1.2", but an
* implementation may return other strings if some other protocol is used.
*/
Protocol,
/** Number of key bits used by the encryption algorithm. */
KeyBits,
/**
* A short name of the ciphersuite used, e.g. "DHE-RSA-DES-CBC3-SHA". The names are specific to
* each SSL implementation.
*/
Cipher,
/**
* If SSL compression is in use, returns the name of the compression algorithm, or "on" if
* compression is used but the algorithm is not known. If compression is not in use, returns
* "off".
*/
Compression,
/**
* Application protocol selected by the TLS Application-Layer Protocol Negotiation (ALPN)
* extension. The only protocol supported by libpq is postgresql, so this is mainly useful for
* checking whether the server supported ALPN or not. Empty string if ALPN was not used.
*/
Alpn,
}
impl std::fmt::Display for Attribute {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = format!("{self:?}").to_lowercase();
f.write_str(&s)
}
}
#[doc(hidden)]
impl TryFrom<&String> for Attribute {
type Error = crate::errors::Error;
fn try_from(value: &String) -> Result<Self, Self::Error> {
let attribute = match value.as_str() {
"library" => Self::Library,
"protocol" => Self::Protocol,
"key_bits" => Self::KeyBits,
"cipher" => Self::Cipher,
"compression" => Self::Compression,
"alpn" => Self::Alpn,
_ => return Err(crate::errors::Error::InvalidSslAttribute(value.clone())),
};
Ok(attribute)
}
}