Skip to content

Commit bace1ca

Browse files
authored
Merge pull request #65 from cxw620/use-rustls-kernel-connection-1-fmt
style: apply rustfmt config
2 parents e159023 + 3b436ad commit bace1ca

File tree

7 files changed

+64
-48
lines changed

7 files changed

+64
-48
lines changed

.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[alias]
2+
fmt-unstable = ["fmt", "--all", "--", "--config-path", ".rustfmt.unstable.toml"]

.rustfmt.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# keep in sync with .rustfmt.unstable.toml
2+
chain_width = 40
3+
style_edition = "2021"

.rustfmt.unstable.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# keep in sync with .rustfmt.toml
2+
chain_width = 40
3+
style_edition = "2021"
4+
5+
# format imports
6+
group_imports = "StdExternalCrate"
7+
imports_granularity = "Module"

ktls/src/cork_stream.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use std::{io, pin::Pin, task};
1+
use std::pin::Pin;
2+
use std::{io, task};
23

34
use rustls::internal::msgs::codec::Codec;
45
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};

ktls/src/ffi.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use std::os::unix::prelude::RawFd;
22

33
use ktls_sys::bindings as ktls;
4-
use rustls::{
5-
internal::msgs::{enums::AlertLevel, message::Message},
6-
AlertDescription, ConnectionTrafficSecrets, SupportedCipherSuite,
7-
};
4+
use rustls::internal::msgs::enums::AlertLevel;
5+
use rustls::internal::msgs::message::Message;
6+
use rustls::{AlertDescription, ConnectionTrafficSecrets, SupportedCipherSuite};
87

98
pub(crate) const TLS_1_2_VERSION_NUMBER: u16 = (((ktls::TLS_1_2_VERSION_MAJOR & 0xFF) as u16) << 8)
109
| ((ktls::TLS_1_2_VERSION_MINOR & 0xFF) as u16);

ktls/src/ktls_stream.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
use nix::{
2-
errno::Errno,
3-
sys::socket::{recvmsg, ControlMessageOwned, MsgFlags, SockaddrIn, TlsGetRecordType},
4-
};
5-
use num_enum::FromPrimitive;
6-
use std::{
7-
io::{self, IoSliceMut},
8-
os::unix::prelude::AsRawFd,
9-
pin::Pin,
10-
task,
11-
};
1+
use std::io::{self, IoSliceMut};
2+
use std::os::unix::prelude::AsRawFd;
3+
use std::pin::Pin;
4+
use std::task;
125

6+
use nix::errno::Errno;
7+
use nix::sys::socket::{ControlMessageOwned, MsgFlags, SockaddrIn, TlsGetRecordType, recvmsg};
8+
use num_enum::FromPrimitive;
139
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
1410

1511
use crate::AsyncReadReady;
@@ -163,7 +159,10 @@ where
163159
}
164160
TlsGetRecordType::Alert => {
165161
// the alert level and description are in iovs
166-
let iov = r.iovs().next().expect("expected data in iovs");
162+
let iov = r
163+
.iovs()
164+
.next()
165+
.expect("expected data in iovs");
167166

168167
let (level, description) = match iov {
169168
[] => {
@@ -230,7 +229,9 @@ where
230229
);
231230
}
232231
TlsGetRecordType::ApplicationData => {
233-
unreachable!("received TLS application in recvmsg, this is supposed to happen in the poll_read codepath")
232+
unreachable!(
233+
"received TLS application in recvmsg, this is supposed to happen in the poll_read codepath"
234+
)
234235
}
235236
TlsGetRecordType::Unknown(t) => {
236237
// just ignore the record?

ktls/src/lib.rs

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
1-
use ffi::{setup_tls_info, setup_ulp, KtlsCompatibilityError};
2-
use futures_util::future::try_join_all;
3-
use ktls_sys::bindings as sys;
4-
use rustls::{Connection, SupportedCipherSuite, SupportedProtocolVersion};
5-
61
#[cfg(all(not(feature = "ring"), not(feature = "aws_lc_rs")))]
72
compile_error!("This crate needs wither the 'ring' or 'aws_lc_rs' feature enabled");
83
#[cfg(all(feature = "ring", feature = "aws_lc_rs"))]
94
compile_error!("The 'ring' and 'aws_lc_rs' features are mutually exclusive");
5+
6+
mod async_read_ready;
7+
mod cork_stream;
8+
mod ffi;
9+
mod ktls_stream;
10+
11+
use std::future::Future;
12+
use std::io;
13+
use std::net::SocketAddr;
14+
use std::os::unix::prelude::{AsRawFd, RawFd};
15+
16+
use futures_util::future::try_join_all;
17+
use ktls_sys::bindings as sys;
1018
#[cfg(feature = "aws_lc_rs")]
1119
use rustls::crypto::aws_lc_rs::cipher_suite;
1220
#[cfg(feature = "ring")]
1321
use rustls::crypto::ring::cipher_suite;
14-
22+
use rustls::{Connection, SupportedCipherSuite, SupportedProtocolVersion};
1523
use smallvec::SmallVec;
16-
use std::{
17-
future::Future,
18-
io,
19-
net::SocketAddr,
20-
os::unix::prelude::{AsRawFd, RawFd},
21-
};
22-
use tokio::{
23-
io::{AsyncRead, AsyncReadExt, AsyncWrite},
24-
net::{TcpListener, TcpStream},
25-
};
24+
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite};
25+
use tokio::net::{TcpListener, TcpStream};
2626

27-
mod ffi;
27+
pub use crate::async_read_ready::AsyncReadReady;
28+
pub use crate::cork_stream::CorkStream;
2829
pub use crate::ffi::CryptoInfo;
29-
30-
mod async_read_ready;
31-
pub use async_read_ready::AsyncReadReady;
32-
33-
mod ktls_stream;
34-
pub use ktls_stream::KtlsStream;
35-
36-
mod cork_stream;
37-
pub use cork_stream::CorkStream;
30+
use crate::ffi::{KtlsCompatibilityError, setup_tls_info, setup_ulp};
31+
pub use crate::ktls_stream::KtlsStream;
3832

3933
#[derive(Debug, Default)]
4034
pub struct CompatibleCiphers {
@@ -70,7 +64,9 @@ impl CompatibleCiphers {
7064
}
7165
};
7266

73-
ciphers.test_ciphers(local_addr, accept_conns_fut).await?;
67+
ciphers
68+
.test_ciphers(local_addr, accept_conns_fut)
69+
.await?;
7470

7571
Ok(ciphers)
7672
}
@@ -252,7 +248,9 @@ where
252248
IO: AsRawFd + AsyncRead + AsyncReadReady + AsyncWrite + Unpin,
253249
{
254250
stream.get_mut().0.corked = true;
255-
let drained = drain(&mut stream).await.map_err(Error::DrainError)?;
251+
let drained = drain(&mut stream)
252+
.await
253+
.map_err(Error::DrainError)?;
256254
let (io, conn) = stream.into_inner();
257255
let io = io.io;
258256

@@ -273,7 +271,9 @@ where
273271
IO: AsRawFd + AsyncRead + AsyncWrite + Unpin,
274272
{
275273
stream.get_mut().0.corked = true;
276-
let drained = drain(&mut stream).await.map_err(Error::DrainError)?;
274+
let drained = drain(&mut stream)
275+
.await
276+
.map_err(Error::DrainError)?;
277277
let (io, conn) = stream.into_inner();
278278
let io = io.io;
279279

@@ -290,7 +290,10 @@ async fn drain(stream: &mut (impl AsyncRead + Unpin)) -> std::io::Result<Option<
290290

291291
loop {
292292
tracing::trace!("stream.read called");
293-
let n = match stream.read(&mut drained[filled..]).await {
293+
let n = match stream
294+
.read(&mut drained[filled..])
295+
.await
296+
{
294297
Ok(n) => n,
295298
Err(ref e) if e.kind() == std::io::ErrorKind::UnexpectedEof => {
296299
// actually this is expected for us!

0 commit comments

Comments
 (0)