Skip to content

Commit

Permalink
feat: add file loader helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAlcibiades committed Sep 11, 2024
1 parent fb2cc7f commit 116c27d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/tls.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{fs, io};
use rustls::pki_types::{CertificateDer, PrivateKeyDer};
use crate::Error;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_rustls::TlsAcceptor;
Expand Down Expand Up @@ -51,3 +53,23 @@ where
}
})
}

// Load the public certificate from a file.
fn load_certs(filename: &str) -> io::Result<Vec<CertificateDer<'static>>> {
// Open certificate file.
let certfile = fs::File::open(filename).unwrap();
let mut reader = io::BufReader::new(certfile);

// Load and return certificate.
rustls_pemfile::certs(&mut reader).collect()
}

// Load the private key from a file.
fn load_private_key(filename: &str) -> io::Result<PrivateKeyDer<'static>> {
// Open keyfile.
let keyfile = fs::File::open(filename).unwrap();
let mut reader = io::BufReader::new(keyfile);

// Load and return a single private key.
rustls_pemfile::private_key(&mut reader).map(|key| key.unwrap())
}

0 comments on commit 116c27d

Please sign in to comment.