libpq/ssl.rs
1#[derive(Clone, Copy, Debug, Eq, PartialEq)]
2pub enum Attribute {
3 /** Name of the SSL implementation in use. (Currently, only "OpenSSL" is implemented) */
4 Library,
5 /**
6 * SSL/TLS version in use. Common values are "TLSv1", "TLSv1.1" and "TLSv1.2", but an
7 * implementation may return other strings if some other protocol is used.
8 */
9 Protocol,
10 /** Number of key bits used by the encryption algorithm. */
11 KeyBits,
12 /**
13 * A short name of the ciphersuite used, e.g. "DHE-RSA-DES-CBC3-SHA". The names are specific to
14 * each SSL implementation.
15 */
16 Cipher,
17 /**
18 * If SSL compression is in use, returns the name of the compression algorithm, or "on" if
19 * compression is used but the algorithm is not known. If compression is not in use, returns
20 * "off".
21 */
22 Compression,
23 /**
24 * Application protocol selected by the TLS Application-Layer Protocol Negotiation (ALPN)
25 * extension. The only protocol supported by libpq is postgresql, so this is mainly useful for
26 * checking whether the server supported ALPN or not. Empty string if ALPN was not used.
27 */
28 Alpn,
29}
30
31impl std::fmt::Display for Attribute {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 let s = format!("{self:?}").to_lowercase();
34 f.write_str(&s)
35 }
36}
37
38#[doc(hidden)]
39impl TryFrom<&String> for Attribute {
40 type Error = crate::errors::Error;
41
42 fn try_from(value: &String) -> Result<Self, Self::Error> {
43 let attribute = match value.as_str() {
44 "library" => Self::Library,
45 "protocol" => Self::Protocol,
46 "key_bits" => Self::KeyBits,
47 "cipher" => Self::Cipher,
48 "compression" => Self::Compression,
49 "alpn" => Self::Alpn,
50 _ => return Err(crate::errors::Error::InvalidSslAttribute(value.clone())),
51 };
52
53 Ok(attribute)
54 }
55}