| 1 | #![allow(dead_code)] |
| 2 | |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#; |
| 4 | |
| 5 | use craterust-analyzer cargo sqlx-core 0.8.3 crate/::errorrust-analyzer cargo sqlx-core 0.8.3 error/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#; |
| 6 | use craterust-analyzer cargo sqlx-core 0.8.3 crate/::netrust-analyzer cargo sqlx-core 0.8.3 net/::socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/::WithSocketrust-analyzer cargo sqlx-core 0.8.3 net/socket/WithSocket#; |
| 7 | use craterust-analyzer cargo sqlx-core 0.8.3 crate/::netrust-analyzer cargo sqlx-core 0.8.3 net/::Socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#; |
| 8 | |
| 9 | #[cfg(feature = "_tls-rustls")] |
| 10 | mod tls_rustlsrust-analyzer cargo sqlx-core 0.8.3 net/tls/tls_rustls/; |
| 11 | |
| 12 | #[cfg(feature = "_tls-native-tls")] |
| 13 | mod tls_native_tlsrust-analyzer cargo sqlx-core 0.8.3 net/tls/tls_native_tls/; |
| 14 | |
| 15 | mod utilrust-analyzer cargo sqlx-core 0.8.3 net/tls/util/; |
| 16 | |
| 17 | /// X.509 Certificate input, either a file path or a PEM encoded inline certificate(s). |
| 18 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 19 | pub enum CertificateInputrust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput# { |
| 20 | /// PEM encoded certificate(s) |
| 21 | Inlinerust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#Inline#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>), |
| 22 | /// Path to a file containing PEM encoded certificate(s) |
| 23 | Filerust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#File#(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#), |
| 24 | } |
| 25 | |
| 26 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> for CertificateInputrust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput# { |
| 27 | fn fromrust-analyzer cargo sqlx-core 0.8.3 net/tls/impl#[CertificateInput][`From<String>`]from().(value: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Selfrust-analyzer cargo sqlx-core 0.8.3 net/tls/impl#[CertificateInput][`From<String>`] { |
| 28 | let trimmed = value.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().(); |
| 29 | // Some heuristics according to https://tools.ietf.org/html/rfc7468 |
| 30 | if trimmed.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("-----BEGIN CERTIFICATE-----") |
| 31 | && trimmed.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("-----END CERTIFICATE-----") |
| 32 | { |
| 33 | CertificateInputrust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#::Inlinerust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#Inline#(value.as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().().to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().()) |
| 34 | } else { |
| 35 | CertificateInputrust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#::Filerust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#File#(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<String>`]from().(value)) |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | impl CertificateInputrust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput# { |
| 41 | async fn datarust-analyzer cargo sqlx-core 0.8.3 net/tls/impl#[CertificateInput]data().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> { |
| 42 | use craterust-analyzer cargo sqlx-core 0.8.3 crate/::fsrust-analyzer cargo sqlx-core 0.8.3 fs/; |
| 43 | match self { |
| 44 | CertificateInputrust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#::Inlinerust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#Inline#(v) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().()), |
| 45 | CertificateInputrust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#::Filerust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#File#(path) => fsrust-analyzer cargo sqlx-core 0.8.3 fs/::readrust-analyzer cargo sqlx-core 0.8.3 fs/read().(path).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll()., |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for CertificateInputrust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput# { |
| 51 | fn fmtrust-analyzer cargo sqlx-core 0.8.3 net/tls/impl#[CertificateInput][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 52 | match self { |
| 53 | CertificateInputrust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#::Inlinerust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#Inline#(v) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(v.as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().())), |
| 54 | CertificateInputrust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#::Filerust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#File#(path) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "file: {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()), |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | pub struct TlsConfigrust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig#<'a> { |
| 60 | pub accept_invalid_certsrust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig#accept_invalid_certs.: bool, |
| 61 | pub accept_invalid_hostnamesrust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig#accept_invalid_hostnames.: bool, |
| 62 | pub hostnamerust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig#hostname.: &'a str, |
| 63 | pub root_cert_pathrust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig#root_cert_path.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a CertificateInputrust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#>, |
| 64 | pub client_cert_pathrust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig#client_cert_path.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a CertificateInputrust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#>, |
| 65 | pub client_key_pathrust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig#client_key_path.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a CertificateInputrust-analyzer cargo sqlx-core 0.8.3 net/tls/CertificateInput#>, |
| 66 | } |
| 67 | |
| 68 | pub async fn handshakerust-analyzer cargo sqlx-core 0.8.3 net/tls/handshake().<S, Ws>( |
| 69 | socket: S, |
| 70 | config: TlsConfigrust-analyzer cargo sqlx-core 0.8.3 net/tls/TlsConfig#<'_>, |
| 71 | with_socket: Ws, |
| 72 | ) -> craterust-analyzer cargo sqlx-core 0.8.3 crate/::Resultrust-analyzer cargo sqlx-core 0.8.3 error/Result#<Ws::Outputrust-analyzer cargo sqlx-core 0.8.3 net/socket/WithSocket#Output#> |
| 73 | where |
| 74 | S: Socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/Socket#, |
| 75 | Ws: WithSocketrust-analyzer cargo sqlx-core 0.8.3 net/socket/WithSocket#, |
| 76 | { |
| 77 | #[cfg(feature = "_tls-native-tls")] |
| 78 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(with_socket |
| 79 | .with_socketrust-analyzer cargo sqlx-core 0.8.3 net/socket/WithSocket#with_socket().(tls_native_tlsrust-analyzer cargo sqlx-core 0.8.3 net/tls/tls_native_tls/::handshakerust-analyzer cargo sqlx-core 0.8.3 net/tls/tls_native_tls/handshake().(socket, config).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 80 | .await); |
| 81 | |
| 82 | #[cfg(all(feature = "_tls-rustls", not(feature = "_tls-native-tls")))] |
| 83 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(with_socket |
| 84 | .with_socket(tls_rustlsrust-analyzer cargo sqlx-core 0.8.3 net/tls/tls_rustls/::handshakerust-analyzer cargo sqlx-core 0.8.3 net/tls/tls_rustls/handshake().(socket, config).await?) |
| 85 | .await); |
| 86 | |
| 87 | #[cfg(not(any(feature = "_tls-native-tls", feature = "_tls-rustls")))] |
| 88 | { |
| 89 | droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().((socket, config, with_socket)); |
| 90 | panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("one of the `runtime-*-native-tls` or `runtime-*-rustls` features must be enabled") |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | pub fn availablerust-analyzer cargo sqlx-core 0.8.3 net/tls/available().() -> bool { |
| 95 | cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(any(feature = "_tls-native-tls", feature = "_tls-rustls")) |
| 96 | } |
| 97 | |
| 98 | pub fn error_if_unavailablerust-analyzer cargo sqlx-core 0.8.3 net/tls/error_if_unavailable().() -> craterust-analyzer cargo sqlx-core 0.8.3 crate/::Resultrust-analyzer cargo sqlx-core 0.8.3 error/Result#<()> { |
| 99 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().availablerust-analyzer cargo sqlx-core 0.8.3 net/tls/available().() { |
| 100 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#::tlsrust-analyzer cargo sqlx-core 0.8.3 error/impl#[Error]tls().( |
| 101 | "TLS upgrade required by connect options \ |
| 102 | but SQLx was built without TLS support enabled", |
| 103 | )); |
| 104 | } |
| 105 | |
| 106 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 107 | } |