read_bytes -> std::fs::read

This commit is contained in:
Wez Furlong committed 2020-01-20 07:55:51 -08:00
1 parent 22622219c7
commit 7688d669d7
3 files changed
+6 -17

No files matched your search

+1 -2
View File
@@ -405,7 +405,6 @@ impl Reconnectable {
#[cfg(any(feature = "openssl", unix))]
pub fn tls_connect(&mut self, tls_client: TlsDomainClient) -> anyhow::Result<()> {
use crate::server::listener::read_bytes;
use openssl::ssl::{SslConnector, SslFiletype, SslMethod};
use openssl::x509::X509;
@@ -432,7 +431,7 @@ impl Reconnectable {
connector.set_private_key_file(key_file, SslFiletype::PEM)?;
}
fn load_cert(name: &Path) -> anyhow::Result<X509> {
let cert_bytes = read_bytes(name)?;
let cert_bytes = std::fs::read(name)?;
log::trace!("loaded {}", name.display());
Ok(X509::from_pem(&cert_bytes)?)
}
+1 -11
View File
@@ -18,7 +18,6 @@ use rangeset::RangeSet;
use std::collections::{HashMap, HashSet};
use std::convert::TryFrom;
use std::fs::remove_file;
use std::io::Read;
use std::net::TcpListener;
use std::path::{Path, PathBuf};
use std::rc::Rc;
@@ -77,22 +76,13 @@ pub enum IdentitySource {
},
}
pub fn read_bytes<T: AsRef<Path>>(path: T) -> anyhow::Result<Vec<u8>> {
let path = path.as_ref();
let mut f =
std::fs::File::open(path).with_context(|| format!("opening file {}", path.display()))?;
let mut buf = Vec::new();
f.read_to_end(&mut buf)?;
Ok(buf)
}
impl TryFrom<IdentitySource> for Identity {
type Error = Error;
fn try_from(source: IdentitySource) -> anyhow::Result<Identity> {
match source {
IdentitySource::Pkcs12File { path, password } => {
let bytes = read_bytes(&path)?;
let bytes = std::fs::read(&path)?;
Identity::from_pkcs12(&bytes, &password)
.with_context(|| format!("error loading pkcs12 file '{}'", path.display()))
}
+4 -4
View File
@@ -113,7 +113,7 @@ pub fn spawn_tls_listener(tls_server: &TlsDomainServer) -> Result<(), Error> {
acceptor.set_private_key_file(key_file, SslFiletype::PEM)?;
}
fn load_cert(name: &Path) -> anyhow::Result<X509> {
let cert_bytes = read_bytes(name)?;
let cert_bytes = std::fs::read(name)?;
log::trace!("loaded {}", name.display());
Ok(X509::from_pem(&cert_bytes)?)
}
@@ -160,13 +160,13 @@ pub fn pem_files_to_identity(
// We can use openssl to convert the data to pkcs12
// so that we can then pass it on using the Identity
// type that native_tls requires.
let key_bytes = read_bytes(&key)?;
let key_bytes = std::fs::read(&key)?;
let pkey = PKey::private_key_from_pem(&key_bytes)?;
let cert_bytes = read_bytes(cert.as_ref().unwrap_or(&key))?;
let cert_bytes = std::fs::read(cert.as_ref().unwrap_or(&key))?;
let x509_cert = X509::from_pem(&cert_bytes)?;
let chain_bytes = read_bytes(chain.as_ref().unwrap_or(&key))?;
let chain_bytes = std::fs::read(chain.as_ref().unwrap_or(&key))?;
let x509_chain = X509::stack_from_pem(&chain_bytes)?;
let password = "internal";