mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-27 10:46:30 +00:00
use Result::map_err and ? in Tls::new
This commit is contained in:
24
src/tls.rs
24
src/tls.rs
@@ -44,25 +44,17 @@ impl Tls {
|
|||||||
pub fn new() -> Result<Self, Error> {
|
pub fn new() -> Result<Self, Error> {
|
||||||
let config = get_config();
|
let config = get_config();
|
||||||
|
|
||||||
let certs = match load_certs(Path::new(&config.general.tls_certificate.unwrap())) {
|
let certs = load_certs(Path::new(&config.general.tls_certificate.unwrap()))
|
||||||
Ok(certs) => certs,
|
.map_err(|_| Error::TlsError)?;
|
||||||
Err(_) => return Err(Error::TlsError),
|
let key_der = load_keys(Path::new(&config.general.tls_private_key.unwrap()))
|
||||||
};
|
.map_err(|_| Error::TlsError)?
|
||||||
|
.remove(0);
|
||||||
|
|
||||||
let mut keys = match load_keys(Path::new(&config.general.tls_private_key.unwrap())) {
|
let config = rustls::ServerConfig::builder()
|
||||||
Ok(keys) => keys,
|
|
||||||
Err(_) => return Err(Error::TlsError),
|
|
||||||
};
|
|
||||||
|
|
||||||
let config = match rustls::ServerConfig::builder()
|
|
||||||
.with_safe_defaults()
|
.with_safe_defaults()
|
||||||
.with_no_client_auth()
|
.with_no_client_auth()
|
||||||
.with_single_cert(certs, keys.remove(0))
|
.with_single_cert(certs, key_der)
|
||||||
.map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidInput, err))
|
.map_err(|_| Error::TlsError)?;
|
||||||
{
|
|
||||||
Ok(c) => c,
|
|
||||||
Err(_) => return Err(Error::TlsError),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Tls {
|
Ok(Tls {
|
||||||
acceptor: TlsAcceptor::from(Arc::new(config)),
|
acceptor: TlsAcceptor::from(Arc::new(config)),
|
||||||
|
|||||||
Reference in New Issue
Block a user