Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
msrd0 committed Mar 5, 2024
1 parent b8c69b6 commit 0fe21c4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions examples/hello_world_tls/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A Hello World example application for working with Gotham.
use gotham::anyhow;
use gotham::rustls::{self, Certificate, PrivateKey, ServerConfig};
use gotham::rustls::{Certificate, PrivateKey, ServerConfig};
use gotham::state::State;
use rustls_pemfile::{certs, pkcs8_private_keys};
use std::io::BufReader;
Expand All @@ -24,19 +24,19 @@ pub fn main() -> anyhow::Result<()> {
Ok(())
}

fn build_config() -> Result<ServerConfig, rustls::Error> {
fn build_config() -> anyhow::Result<ServerConfig> {
let mut cert_file = BufReader::new(&include_bytes!("cert.pem")[..]);
let mut key_file = BufReader::new(&include_bytes!("key.pem")[..]);
let certs = certs(&mut cert_file)
.unwrap()
.into_iter()
.map(Certificate)
.collect();
let mut keys = pkcs8_private_keys(&mut key_file).unwrap();
.map(|result| result.map(|der| Certificate(der.to_vec())))
.collect::<Result<_, _>>()?;
let mut keys = pkcs8_private_keys(&mut key_file);
let key = PrivateKey(keys.next().unwrap()?.secret_pkcs8_der().to_vec());
ServerConfig::builder()
.with_safe_defaults()
.with_no_client_auth()
.with_single_cert(certs, PrivateKey(keys.remove(0)))
.with_single_cert(certs, key)
.map_err(Into::into)
}

#[cfg(test)]
Expand Down

0 comments on commit 0fe21c4

Please sign in to comment.