Skip to content

Commit

Permalink
Add more documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
c410-f3r committed Oct 29, 2023
1 parent 65160af commit 1aa08ef
Show file tree
Hide file tree
Showing 27 changed files with 143 additions and 123 deletions.
20 changes: 20 additions & 0 deletions .certs/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDMTCCAhmgAwIBAgIUcJ1+HcDRb6j9+M0RdGRvsIZl4+MwDQYJKoZIhvcNAQEL
BQAwHTELMAkGA1UEBhMCRkkxDjAMBgNVBAMMBXZhaGlkMB4XDTIzMTAyODE4MDAw
OVoXDTI0MTAyNzE4MDAwOVowHTELMAkGA1UEBhMCRkkxDjAMBgNVBAMMBXZhaGlk
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApGxnjZ35y7tWQqsqwVD7
F4FOlv5703suM/CP7HFYpzbtVZP6ANfZQ8q+ymhfKJY5gF+6Cq1gP1S+Nj6TzHT0
08EGXmzL4IQAVgK4bLlJp/L0qltVosp2odoAtsPdM7ETuZUVqgdC3QDklLo5a3Z5
NvYrn7WOC9kuyck407jIClzc/xzF0KzC5oA0URc26p+Rbq7ARNULY0W5nw4PkoXc
EMMc2HXsw/3/Py9EeCNBCy2+62tG08Q4te6VbxKig5Kgl9wWMM58j0wnrsb8OU13
2SqzU6JdZvwoXxgeHWojGJTEU+TOfij99w8MRi66R+y10YE5hgbEuK0/ZsgIyv0B
fwIDAQABo2kwZzAfBgNVHSMEGDAWgBTWUjGbMDyGa7exN3NRamzex3tgHjAJBgNV
HRMEAjAAMBoGA1UdEQQTMBGCCWxvY2FsaG9zdIcEfwAAATAdBgNVHQ4EFgQUQX++
J213hH3Hqub8Lr+k+z7jH1IwDQYJKoZIhvcNAQELBQADggEBAEtD8FxWnKC35OH5
NmEnOTEF+pQvHVc3im/iXT+VAhrWjMHDzAgHn3Qyyn3GYUB11uv57ONcEIW3XCDm
++Qyg+t9URox0qVhY5pzzJEn7JVjndXMKd7+BRjrnBNJYKnOxj+mq5ZQ1jdvvWmo
aeu4ctknGyde6Gc1tEeeaENlzobiH0/uh9Iu/jq50HsW5DvWkh6HCo4YqfTEHnE1
8Icw9eSEmMc/pdhCfxJ8wjrn/adpW0NR8WOnyanSr6jLgLH/a2+PFKzNMshy7m3D
zLP/GyKx/5wDuKh1bXRrh6dGWSHl5IRrlAXareQadwY+J/7oST4wajmUTJ1gE0Nj
iMUbtSE=
-----END CERTIFICATE-----
28 changes: 28 additions & 0 deletions .certs/key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCkbGeNnfnLu1ZC
qyrBUPsXgU6W/nvTey4z8I/scVinNu1Vk/oA19lDyr7KaF8oljmAX7oKrWA/VL42
PpPMdPTTwQZebMvghABWArhsuUmn8vSqW1Wiynah2gC2w90zsRO5lRWqB0LdAOSU
ujlrdnk29iuftY4L2S7JyTjTuMgKXNz/HMXQrMLmgDRRFzbqn5FursBE1QtjRbmf
Dg+ShdwQwxzYdezD/f8/L0R4I0ELLb7ra0bTxDi17pVvEqKDkqCX3BYwznyPTCeu
xvw5TXfZKrNTol1m/ChfGB4daiMYlMRT5M5+KP33DwxGLrpH7LXRgTmGBsS4rT9m
yAjK/QF/AgMBAAECggEAThtzG8qiWd497YC7WEccaH+UMlVkxEM9YQ4TiKoVh6Wn
m+ImPpVLEBG1jZiEL9chLLMMwTq4QI2EqGcUtekPTrJg0KVVOmvqbvFu47MnYsGe
6Xhm12TfcyaI9UlZAM/LQ3snZfR6Fltwupg2Y67NiUbq1T0dY9KBj/jnZmhemtDc
VPgwfOdIsSB4UbFkBz3YrqHOwwz0ORNI0Sk84tjweXBj8Idi+/FG+AEVfFxt5LA0
YHGr7M+6Wu7pSNEMgFfAr3gxyhIM0SHj5iaF7FLSIhu5gYCznp45U+A1ss3xh6Jb
BRKQlxK+EJEEX0thtiz9KFr0aoDTNDSQyngbOhV/QQKBgQDVdpmgxd8sbMTLu1Ky
4k2zQfwN7A17hZYPLPNobKEUbcGp/LBl0cTHGYORastqiA2PCZrrlZLHHEvAlVWO
e76CwrIcE8aUj2GwfKlfy01o+shqWTK0IQNHD+d6tqY6dYe1BvBhWPQVAw1fV74E
z+clj+hagxQ01qWH21XzbhzwPwKBgQDFMCLkRP6TNjVPQ+xXdYZ5gGhM+c+wJh4i
JKCYfGEwn7SMhuiMZj4c2U7iIPfCX5GrxovaNHbTzhzO9Pp2vUgYsQeDO4THyO5/
qj/Ag1t0x65+f9bHm/GvfW5ndMvoKdic29XksGGFtD/drrodY7z+VnUwje7zUorI
N2VbW9uewQKBgEN5ld5ILd9xElQEBoQdHMqJFQ+hijF9bI2ne9mKXPCEMS92fJvy
zuzQl9Ijm+E02HRaaOoHAbqGqztY+Q5s9y+GM57EcYUMPaj3/uIU9Yc1npxfTbO6
q7qOwHD9w1W/SQJkCx/6ak0qBdQZfCsxPLOW5a+Wt5BsOS7Umjq0l9kpAoGABWgl
fMbbiCPTYGIHZ/qD/m7j7UBoTnctGliQwr2eWJv4cmX8mGTxTQ80V4T55i2CrAgc
q5YGsBYVuiMDfx//ixXHk/Sc1nGPAJclelzftBsJkNRmikCfZuV0koekU7BaDSsF
+WhQtD7WBXkWB1pFw1+RhQxPQgLAZW8Ha3LgWcECgYBgW5Kzg+sxnAxCMvJZsUcU
pfNK6+Jnt0osVE/TB0lW8hsw3WbuHlI3/tE0vglDfUSt/UvdcYnq5gGe1CGoPPft
/Y2g2CzjT0C9ezK5K6wARiqXKQrrNp2cwE+145jeWAUiCCrlY5f1rGdCxLIGAU+a
yLVUVHQ7M/rm5JUNq6Fx5A==
-----END PRIVATE KEY-----
19 changes: 19 additions & 0 deletions .certs/root-ca.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIDGzCCAgOgAwIBAgIUc4NyGgiEtPpz0I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28 changes: 28 additions & 0 deletions .certs/root-ca.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDQgPTpwlseVnEY
DvicwknNF+PKSYzzGwX73rjgbd/eds849+IotYOWTzTIHXiDsZV76bfFjBuXifWR
1AGHLl/PgoiDffYnGprxAjVJEQGVUL/brK7YdeLXDuY9o0zyKYgjkakGQbJHYOrV
npt4Sdj4XUsUuz5ahG2AulJs4TeV6o487pJeMcWIKS7yIjL25WJbvhgxyrbWUfSW
a4drVOM7AgZ8pmhK736qI5coc7F4ZV6OWCvOILFkMsCG02Ir9MtkbbtMWGOTaZvf
9SK7Kfx5dZ3X6aHe98G2ZQsBH2aJMchYqkSSQHVNiVyCDAfXAHMedbFI7RKZ2PEz
RPs7Mcj5AgMBAAECggEAVEr+OI7xhXdO63oJ+l31tiulVL+dcx8GsUfemCTzb526
sv5L+UdAtoC5BvobIaqmk1zuhbfZ487Lb7Q1FfCinWLZS8edvztbTnolDrAIYtQt
bGMIoMwv89+7J0ogrnop5q9ZlQT0TTUaW1hu5Bd+1xHoa64zTCbjmjo5XnlCnqFk
siTXjSNonotCJjpouxsyL8NqTdvS26FJBDLL+VmsV0bU5CeWc2J85N/Z2XaPGgfD
8cKbNkv21qZFEZe6pf3Nv98YOQ5wQ7/aTxlIMr3lm7xcpiI1GIsDVIesNRlKFZT3
q/t54snlfeBs8ACcHLC/eu2v3OkrZs7hORsU0y3bXQKBgQDXaoc8M8KKjoOn6fZI
/43I9xMWRweLt1hvOkV81lb6ychqjqlSpDEqVEOu6QZaphDnPAXfK5WiMmtzV0S3
+DTnuZNR0ZmfKi4vhx9uq60plFvAGuOH2zTAccNrGu0uPCgYAcsf09mFX8+ugFB+
CksLsIjNtFWtrXxJQGJ+q4vQIwKBgQD3yQuitbwdZk8StDiP6NSMRblMF1K9555a
EZFghp4tiYOes+x/loVvimuOw1nQ6FAPdR6RdbCHLvJKloUHgMgsHiJnd+D347MK
a8vEi0JsDdPXKc1h3X+VVghu1jXIlAGW5jV+8o+N7VbxiCDkxqlTGm7CuSIt1txe
5xWPxteGMwKBgQCMdsxD90RNcOxsW2Ta6LidaG6rwhkrg5xIuuiApIsG8PiccvX6
C1J71YJk1VHtXgf7n+n8QcFKiDIEfc0zYMeuqhVj7paLcMe4+hUG5y78w96n/2CK
P+e/7O6OMnqiAVvre4/l6xAVpgoYMVdLOI8CylQKPiL4Iv2+DhurmVSLnQKBgErn
+CCEGA47M4RP/xliJX8SROX/1v+Z2YEY9n3btE3H2IZNlh0r/8Kscb+CxtAkqq9B
lLAch/UV+CEcR7Lw95J+uZ/V2aiWqTVpSPxtrPLFa1kMRg5jy4H1tC7tiuzL8X8Q
sPNjmIorSbFSmb8PX3jD8N/k37RD0/LMoPQKBHWJAoGAXJiKVo+tVo19UiWw4rGe
XwPNLxjCK1hMni+JG8jBeObjQ9fkq+TIKz6bRh6ccWs3yK+fsfBfYN7Ff4/BJlgc
TqM6hdvqNNYX4NiuO222bej/V9FWc0t1WEYpSb4VuoXZd+kr4goULR5qCHBIhpCt
BTbSU69CGGQcViQEVkGalXw=
-----END PRIVATE KEY-----
4 changes: 2 additions & 2 deletions .scripts/gen-certs.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

openssl req -newkey rsa:2048 -nodes -subj "/C=FI/CN=vahid" -keyout key.pem -out key.csr
openssl x509 -signkey key.pem -in key.csr -req -days 365 -out cert.pem
openssl req -x509 -sha256 -nodes -subj "/C=FI/CN=vahid" -days 1825 -newkey rsa:2048 -keyout root-ca.key -out root-ca.crt
openssl req -x509 -sha256 -nodes -subj "/C=FI/CN=vahid" -days 365 -newkey rsa:2048 -keyout root-ca.key -out root-ca.crt
cat <<'EOF' >> localhost.ext
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
subjectAltName = @alt_names
[alt_names]
DNS.1 = server
DNS.1 = localhost
IP.1 = 127.0.0.1
EOF
openssl x509 -req -CA root-ca.crt -CAkey root-ca.key -in key.csr -out cert.pem -days 365 -CAcreateserial -extfile localhost.ext
Expand Down
3 changes: 1 addition & 2 deletions .scripts/internal-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ cargo install rust-tools --git https://github.com/c410-f3r/regular-crates

rt='rust-tools --template you-rust'

RUSTFLAGS="$($rt rust-flags)"

export CARGO_TARGET_DIR="$($rt target-dir)"
export RUST_BACKTRACE=1
export RUST_LOG=debug
export RUSTFLAGS="$($rt rust-flags)"

$rt rustfmt
$rt clippy
Expand Down
2 changes: 2 additions & 0 deletions wtx-ui/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! WTX - Cli
#[cfg(feature = "clap")]
mod clap;
mod misc;
Expand Down
20 changes: 0 additions & 20 deletions wtx/examples/cert.pem

This file was deleted.

28 changes: 0 additions & 28 deletions wtx/examples/key.pem

This file was deleted.

19 changes: 0 additions & 19 deletions wtx/examples/root-ca.crt

This file was deleted.

28 changes: 0 additions & 28 deletions wtx/examples/root-ca.key

This file was deleted.

2 changes: 1 addition & 1 deletion wtx/examples/web-socket-client-cli-raw-tokio-rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use wtx::{
UriParts,
};

static ROOT_CA: &[u8] = include_bytes!("./root-ca.crt");
static ROOT_CA: &[u8] = include_bytes!("../../.certs/root-ca.crt");

#[tokio::main(flavor = "current_thread")]
async fn main() -> wtx::Result<()> {
Expand Down
15 changes: 10 additions & 5 deletions wtx/examples/web-socket-server-echo-raw-tokio-rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use tokio_rustls::{
TlsAcceptor,
};

static CERT: &[u8] = include_bytes!("./cert.pem");
static KEY: &[u8] = include_bytes!("./key.pem");
static CERT: &[u8] = include_bytes!("../../.certs/cert.pem");
static KEY: &[u8] = include_bytes!("../../.certs/key.pem");

#[tokio::main(flavor = "current_thread")]
async fn main() -> wtx::Result<()> {
Expand All @@ -23,9 +23,14 @@ async fn main() -> wtx::Result<()> {
let local_tls_acceptor = tls_acceptor.clone();
let _jh = tokio::spawn(async move {
let fun = || async move {
let stream = local_tls_acceptor.accept(stream).await?;
common::_accept_conn_and_echo_frames((), &mut <_>::default(), &mut <_>::default(), stream)
.await
let tls_stream = local_tls_acceptor.accept(stream).await?;
common::_accept_conn_and_echo_frames(
(),
&mut <_>::default(),
&mut <_>::default(),
tls_stream,
)
.await
};
if let Err(err) = fun().await {
println!("{err}");
Expand Down
4 changes: 2 additions & 2 deletions wtx/src/array_chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ impl<'slice, T, const N: usize> ArrayChunksMut<'slice, T, N> {
assert!(N != 0, "chunk size must be non-zero");
let len = slice.len() / N;
let (multiple_of_n, remainder) = slice.split_at_mut(len * N);
// SAFETY: We cast a slice of `new_len * N` elements into
// a slice of `new_len` many `N` elements chunks.
// SAFETY: `N` is not zero and `slice` is multiple of `N`.
#[allow(unsafe_code)]
let array_slice = unsafe { slice::from_raw_parts_mut(multiple_of_n.as_mut_ptr().cast(), len) };
Self { iter: array_slice.iter_mut(), remainder }
}
Expand Down
2 changes: 1 addition & 1 deletion wtx/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use core::ops::{Deref, DerefMut};

/// Internal buffer not intended for public usage
#[derive(Debug, Default)]
pub struct Buffer {
pub(crate) struct Buffer {
buffer: Vec<u8>,
len: usize,
}
Expand Down
4 changes: 4 additions & 0 deletions wtx/src/http/header.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/// HTTP header.
pub trait Header {
/// Name.
fn name(&self) -> &[u8];

/// Value.
fn value(&self) -> &[u8];
}

Expand Down Expand Up @@ -31,6 +34,7 @@ where
}
}

/// HTTP/1 header.
pub trait Http1Header: Header {}

impl Http1Header for () {}
Expand Down
8 changes: 4 additions & 4 deletions wtx/src/http/httparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use crate::http::{Header, Http1Header, Request, Response, Version};

impl<'buffer> Header for httparse::Header<'buffer> {
impl Header for httparse::Header<'_> {
#[inline]
fn name(&self) -> &[u8] {
self.name.as_bytes()
Expand All @@ -17,9 +17,9 @@ impl<'buffer> Header for httparse::Header<'buffer> {
}
}

impl<'buffer> Http1Header for httparse::Header<'buffer> {}
impl Http1Header for httparse::Header<'_> {}

impl<'buffer, 'headers> Request for httparse::Request<'headers, 'buffer> {
impl Request for httparse::Request<'_, '_> {
#[inline]
fn method(&self) -> &[u8] {
if let Some(el) = self.method {
Expand Down Expand Up @@ -50,7 +50,7 @@ impl<'buffer, 'headers> Request for httparse::Request<'headers, 'buffer> {
}
}

impl<'buffer, 'headers> Response for httparse::Response<'headers, 'buffer> {
impl Response for httparse::Response<'_, '_> {
#[inline]
fn code(&self) -> u16 {
if let Some(el) = self.code {
Expand Down
1 change: 1 addition & 0 deletions wtx/src/http/request.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::http::Version;

/// HTTP request.
pub trait Request {
/// Method
fn method(&self) -> &[u8];
Expand Down
1 change: 1 addition & 0 deletions wtx/src/http/response.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::http::Version;

/// HTTP response
pub trait Response {
/// Code
fn code(&self) -> u16;
Expand Down
1 change: 1 addition & 0 deletions wtx/src/pool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// Implements external pool traits.
///
/// This structure only exists because tuples are not fundamental.
#[derive(Debug)]
pub struct PoolElem<T>(
/// Element
pub T,
Expand Down
1 change: 1 addition & 0 deletions wtx/src/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl Default for StaticRng {
}
let elem = Box::new(Foo { _bar: 1, _baz: 2 });
// SAFETY: Memory location is not relevant
#[allow(unsafe_code)]
let n: usize = unsafe {
let ref_ptr = ptr::addr_of!(elem);
*ref_ptr.cast()
Expand Down
4 changes: 2 additions & 2 deletions wtx/src/web_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,9 +900,9 @@ where
}

#[inline]
async fn read_first_frame<'fb, B>(
async fn read_first_frame<B>(
&mut self,
fb: &'fb mut FrameBuffer<B>,
fb: &mut FrameBuffer<B>,
header_buffer_len: u8,
payload_start_idx: usize,
) -> crate::Result<Option<ReadFrameInfo>>
Expand Down
Loading

0 comments on commit 1aa08ef

Please sign in to comment.