Moved function to another file

This commit is contained in:
int 80h
2020-04-21 21:09:57 -04:00
parent 6e71a4194a
commit a3d3cc7214
2 changed files with 10 additions and 10 deletions

View File

@@ -25,15 +25,6 @@ use url::Url;
mod config;
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> {
let meta = fs::metadata(&path).expect("Unable to read metadata");
if meta.is_file() {
@@ -132,7 +123,7 @@ fn main() -> io::Result<()> {
.build()?;
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));

View File

@@ -13,6 +13,15 @@ use tokio_rustls::rustls::{Certificate, NoClientAuth, PrivateKey, ServerConfig};
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>> {
certs(&mut BufReader::new(File::open(path)?))
.map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, "invalid cert"))