Skip to content

Commit 2b2965e

Browse files
committed
rustfmt, logging in tests to see rustls errors
1 parent 3bba705 commit 2b2965e

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ tokio-rustls = "0.12.1"
1818
webpki = "0.21.0"
1919

2020
[dev-dependencies]
21+
env_logger = { version = "0.7.1", default-features = false }
2122
tokio = { version = "0.2.6", features = ["macros"] }

src/lib.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
2-
io,
32
future::Future,
3+
io,
44
mem::MaybeUninit,
55
pin::Pin,
66
sync::Arc,
@@ -16,14 +16,15 @@ use tokio_postgres::tls::{ChannelBinding, MakeTlsConnect, TlsConnect};
1616
use tokio_rustls::{client::TlsStream, TlsConnector};
1717
use webpki::{DNSName, DNSNameRef};
1818

19-
2019
pub struct MakeRustlsConnect {
2120
config: Arc<ClientConfig>,
2221
}
2322

2423
impl MakeRustlsConnect {
2524
pub fn new(config: ClientConfig) -> Self {
26-
Self { config: Arc::new(config) }
25+
Self {
26+
config: Arc::new(config),
27+
}
2728
}
2829
}
2930

@@ -59,7 +60,8 @@ where
5960
type Future = Pin<Box<dyn Future<Output = io::Result<RustlsStream<S>>>>>;
6061

6162
fn connect(self, stream: S) -> Self::Future {
62-
self.connector.connect(self.hostname.as_ref(), stream)
63+
self.connector
64+
.connect(self.hostname.as_ref(), stream)
6365
.map_ok(|s| RustlsStream(Box::pin(s)))
6466
.boxed()
6567
}
@@ -77,7 +79,7 @@ where
7779
Some(certs) if certs.len() > 0 => {
7880
let sha256 = digest::digest(&digest::SHA256, certs[0].as_ref());
7981
ChannelBinding::tls_server_end_point(sha256.as_ref().into())
80-
},
82+
}
8183
_ => ChannelBinding::none(),
8284
}
8385
}
@@ -87,15 +89,23 @@ impl<S> AsyncRead for RustlsStream<S>
8789
where
8890
S: AsyncRead + AsyncWrite + Unpin,
8991
{
90-
fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context, buf: &mut [u8]) -> Poll<tokio::io::Result<usize>> {
92+
fn poll_read(
93+
mut self: Pin<&mut Self>,
94+
cx: &mut Context,
95+
buf: &mut [u8],
96+
) -> Poll<tokio::io::Result<usize>> {
9197
self.0.as_mut().poll_read(cx, buf)
9298
}
9399

94100
unsafe fn prepare_uninitialized_buffer(&self, buf: &mut [MaybeUninit<u8>]) -> bool {
95101
self.0.prepare_uninitialized_buffer(buf)
96102
}
97103

98-
fn poll_read_buf<B: BufMut>(mut self: Pin<&mut Self>, cx: &mut Context, buf: &mut B) -> Poll<tokio::io::Result<usize>>
104+
fn poll_read_buf<B: BufMut>(
105+
mut self: Pin<&mut Self>,
106+
cx: &mut Context,
107+
buf: &mut B,
108+
) -> Poll<tokio::io::Result<usize>>
99109
where
100110
Self: Sized,
101111
{
@@ -107,7 +117,11 @@ impl<S> AsyncWrite for RustlsStream<S>
107117
where
108118
S: AsyncRead + AsyncWrite + Unpin,
109119
{
110-
fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context, buf: &[u8]) -> Poll<tokio::io::Result<usize>> {
120+
fn poll_write(
121+
mut self: Pin<&mut Self>,
122+
cx: &mut Context,
123+
buf: &[u8],
124+
) -> Poll<tokio::io::Result<usize>> {
111125
self.0.as_mut().poll_write(cx, buf)
112126
}
113127

@@ -119,7 +133,11 @@ where
119133
self.0.as_mut().poll_shutdown(cx)
120134
}
121135

122-
fn poll_write_buf<B: Buf>(mut self: Pin<&mut Self>, cx: &mut Context, buf: &mut B) -> Poll<tokio::io::Result<usize>>
136+
fn poll_write_buf<B: Buf>(
137+
mut self: Pin<&mut Self>,
138+
cx: &mut Context,
139+
buf: &mut B,
140+
) -> Poll<tokio::io::Result<usize>>
123141
where
124142
Self: Sized,
125143
{
@@ -133,11 +151,16 @@ mod tests {
133151

134152
#[tokio::test]
135153
async fn it_works() {
154+
env_logger::builder().is_test(true).try_init().unwrap();
155+
136156
let config = rustls::ClientConfig::new();
137157
let tls = super::MakeRustlsConnect::new(config);
138-
let (client, conn) = tokio_postgres::connect("sslmode=require host=localhost user=postgres", tls).await.unwrap();
158+
let (client, conn) =
159+
tokio_postgres::connect("sslmode=require host=localhost user=postgres", tls)
160+
.await
161+
.expect("connect");
139162
tokio::spawn(conn.map_err(|e| panic!("{:?}", e)));
140-
let stmt = client.prepare("SELECT 1").await.unwrap();
141-
let _ = client.query(&stmt, &[]).await.unwrap();
163+
let stmt = client.prepare("SELECT 1").await.expect("prepare");
164+
let _ = client.query(&stmt, &[]).await.expect("query");
142165
}
143166
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy