Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(bindings): move tokio examples to dedicated folder #4954

Merged
merged 6 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/rust-examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = [
"client-hello-config-resolution",
"client-hello-config-resolution", "tokio-server-client",
]
resolver = "2"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ struct Cli {
async fn main() -> Result<(), Box<dyn Error>> {
let args = Cli::parse();
let mut config = s2n_tls::config::Config::builder();
let ca: Vec<u8> = std::fs::read(env!("CARGO_MANIFEST_DIR").to_owned() + "/certs/ca-cert.pem")?;
let ca: Vec<u8> =
std::fs::read(env!("CARGO_MANIFEST_DIR").to_owned() + "/../certs/ca-cert.pem")?;
config.set_security_policy(&DEFAULT_TLS13)?;
config.trust_pem(&ca)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ impl ClientHelloCallback for AnimalConfigResolver {
}

fn server_config(animal: &str) -> s2n_tls::config::Config {
let cert_path = format!("{}/certs/{}-chain.pem", env!("CARGO_MANIFEST_DIR"), animal);
let key_path = format!("{}/certs/{}-key.pem", env!("CARGO_MANIFEST_DIR"), animal);
let cert_path = format!(
"{}/../certs/{}-chain.pem",
env!("CARGO_MANIFEST_DIR"),
animal
);
let key_path = format!("{}/../certs/{}-key.pem", env!("CARGO_MANIFEST_DIR"), animal);
let cert = std::fs::read(cert_path).unwrap();
let key = std::fs::read(key_path).unwrap();
let mut config = s2n_tls::config::Builder::new();
Expand Down
13 changes: 13 additions & 0 deletions bindings/rust-examples/tokio-server-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "tokio-server-client"
version.workspace = true
authors.workspace = true
publish.workspace = true
license.workspace = true
edition.workspace = true

[dependencies]
s2n-tls = { path = "../../rust/s2n-tls" }
s2n-tls-tokio = { path = "../../rust/s2n-tls-tokio" }
tokio = { version = "1", features = ["full"] }
clap = { version = "4", features = ["derive"] }
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use s2n_tls_tokio::TlsConnector;
use std::{error::Error, fs};
use tokio::{io::AsyncWriteExt, net::TcpStream};

/// NOTE: this certificate is to be used for demonstration purposes only!
const DEFAULT_CERT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/cert.pem");
/// NOTE: this ca is to be used for demonstration purposes only!
const DEFAULT_CA: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/ca-cert.pem");

#[derive(Parser, Debug)]
struct Args {
#[clap(short, long, default_value_t = String::from(DEFAULT_CERT))]
#[clap(short, long, default_value_t = String::from(DEFAULT_CA))]
trust: String,
addr: String,
}
Expand All @@ -29,7 +29,7 @@ async fn run_client(trust_pem: &[u8], addr: &str) -> Result<(), Box<dyn Error>>

// Connect to the server.
let stream = TcpStream::connect(addr).await?;
let tls = client.connect("localhost", stream).await?;
let tls = client.connect("www.kangaroo.com", stream).await?;
println!("{:#?}", tls);

// Split the stream.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::{error::Error, fs};
use tokio::{io::AsyncWriteExt, net::TcpListener};

/// NOTE: this certificate and key are to be used for demonstration purposes only!
const DEFAULT_CERT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/cert.pem");
const DEFAULT_KEY: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/key.pem");
const DEFAULT_CERT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/kangaroo-chain.pem");
const DEFAULT_KEY: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../certs/kangaroo-key.pem");

#[derive(Parser, Debug)]
struct Args {
Expand Down
1 change: 0 additions & 1 deletion bindings/rust/s2n-tls-tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ tokio = { version = "1", features = ["net", "time"] }

[dev-dependencies]
s2n-tls = { path = "../s2n-tls", features = ["unstable-testing"] }
clap = { version = "3", features = ["derive"] }
rand = { version = "0.8" }
tokio = { version = "1", features = [ "io-std", "io-util", "macros", "net", "rt-multi-thread", "test-util", "time"] }
tokio-macros = "=2.3.0"
Loading