Moved function to another file
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -25,15 +25,6 @@ use url::Url;
|
|||||||
mod config;
|
mod config;
|
||||||
mod tls;
|
mod tls;
|
||||||
|
|
||||||
fn get_tls_config(cfg: config::Config) -> rustls::ServerConfig {
|
|
||||||
let store = rustls::RootCertStore::empty();
|
|
||||||
let verifier = rustls::AllowAnyAnonymousOrAuthenticatedClient::new(store);
|
|
||||||
let mut tls_config = rustls::ServerConfig::new(verifier);
|
|
||||||
tls_config.cert_resolver = Arc::new(tls::CertResolver::from_config(cfg).unwrap());
|
|
||||||
|
|
||||||
tls_config
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_content(mut path: PathBuf, u: url::Url) -> Result<String, io::Error> {
|
fn get_content(mut path: PathBuf, u: url::Url) -> Result<String, io::Error> {
|
||||||
let meta = fs::metadata(&path).expect("Unable to read metadata");
|
let meta = fs::metadata(&path).expect("Unable to read metadata");
|
||||||
if meta.is_file() {
|
if meta.is_file() {
|
||||||
@@ -132,7 +123,7 @@ fn main() -> io::Result<()> {
|
|||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
let handle = runtime.handle().clone();
|
let handle = runtime.handle().clone();
|
||||||
let config = get_tls_config(cfg.clone());
|
let config = tls::get_tls_config(cfg.clone());
|
||||||
|
|
||||||
let acceptor = TlsAcceptor::from(Arc::new(config));
|
let acceptor = TlsAcceptor::from(Arc::new(config));
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,15 @@ use tokio_rustls::rustls::{Certificate, NoClientAuth, PrivateKey, ServerConfig};
|
|||||||
|
|
||||||
use crate::config;
|
use crate::config;
|
||||||
|
|
||||||
|
pub fn get_tls_config(cfg: config::Config) -> rustls::ServerConfig {
|
||||||
|
let store = rustls::RootCertStore::empty();
|
||||||
|
let verifier = rustls::AllowAnyAnonymousOrAuthenticatedClient::new(store);
|
||||||
|
let mut tls_config = rustls::ServerConfig::new(verifier);
|
||||||
|
tls_config.cert_resolver = Arc::new(CertResolver::from_config(cfg).unwrap());
|
||||||
|
|
||||||
|
tls_config
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load_certs(path: &String) -> io::Result<Vec<Certificate>> {
|
pub fn load_certs(path: &String) -> io::Result<Vec<Certificate>> {
|
||||||
certs(&mut BufReader::new(File::open(path)?))
|
certs(&mut BufReader::new(File::open(path)?))
|
||||||
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid cert"))
|
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid cert"))
|
||||||
|
|||||||
Reference in New Issue
Block a user