diff options
Diffstat (limited to 'crates/atuin-server/src/settings.rs')
| -rw-r--r-- | crates/atuin-server/src/settings.rs | 42 |
1 files changed, 1 insertions, 41 deletions
diff --git a/crates/atuin-server/src/settings.rs b/crates/atuin-server/src/settings.rs index b5941c65..db260511 100644 --- a/crates/atuin-server/src/settings.rs +++ b/crates/atuin-server/src/settings.rs @@ -1,7 +1,7 @@ use std::{io::prelude::*, path::PathBuf}; use config::{Config, Environment, File as ConfigFile, FileFormat}; -use eyre::{bail, eyre, Context, Result}; +use eyre::{eyre, Result}; use fs_err::{create_dir_all, File}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; @@ -146,43 +146,3 @@ pub struct Tls { pub cert_path: PathBuf, pub pkey_path: PathBuf, } - -impl Tls { - pub fn certificates(&self) -> Result<Vec<rustls::Certificate>> { - let cert_file = std::fs::File::open(&self.cert_path) - .with_context(|| format!("tls.cert_path {:?} is missing", self.cert_path))?; - let mut reader = std::io::BufReader::new(cert_file); - let certs: Vec<_> = rustls_pemfile::certs(&mut reader) - .map(|c| c.map(|c| rustls::Certificate(c.to_vec()))) - .collect::<Result<Vec<_>, _>>() - .with_context(|| format!("tls.cert_path {:?} is invalid", self.cert_path))?; - - if certs.is_empty() { - bail!( - "tls.cert_path {:?} must have at least one certificate", - self.cert_path - ); - } - - Ok(certs) - } - - pub fn private_key(&self) -> Result<rustls::PrivateKey> { - let pkey_file = std::fs::File::open(&self.pkey_path) - .with_context(|| format!("tls.pkey_path {:?} is missing", self.pkey_path))?; - let mut reader = std::io::BufReader::new(pkey_file); - let keys = rustls_pemfile::pkcs8_private_keys(&mut reader) - .map(|c| c.map(|c| rustls::PrivateKey(c.secret_pkcs8_der().to_vec()))) - .collect::<Result<Vec<_>, _>>() - .with_context(|| format!("tls.pkey_path {:?} is not PKCS8-encoded", self.pkey_path))?; - - if keys.is_empty() { - bail!( - "tls.pkey_path {:?} must have at least one private key", - self.pkey_path - ); - } - - Ok(keys[0].clone()) - } -} |
