aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/api/admin.rs5
-rw-r--r--src/auth.rs5
-rw-r--r--src/config.rs3
-rw-r--r--src/main.rs2
-rw-r--r--src/util.rs10
5 files changed, 6 insertions, 19 deletions
diff --git a/src/api/admin.rs b/src/api/admin.rs
index 19638ef3..2f946fc5 100644
--- a/src/api/admin.rs
+++ b/src/api/admin.rs
@@ -536,15 +536,14 @@ async fn get_release_info(has_http_access: bool, running_within_docker: bool) ->
#[get("/diagnostics")]
async fn diagnostics(_token: AdminToken, ip_header: IpHeader, conn: DbConn) -> ApiResult<Html<String>> {
- use crate::util::read_file_string;
use chrono::prelude::*;
use std::net::ToSocketAddrs;
// Get current running versions
let web_vault_version: WebVaultVersion =
- match read_file_string(&format!("{}/{}", CONFIG.web_vault_folder(), "vw-version.json")) {
+ match std::fs::read_to_string(&format!("{}/{}", CONFIG.web_vault_folder(), "vw-version.json")) {
Ok(s) => serde_json::from_str(&s)?,
- _ => match read_file_string(&format!("{}/{}", CONFIG.web_vault_folder(), "version.json")) {
+ _ => match std::fs::read_to_string(&format!("{}/{}", CONFIG.web_vault_folder(), "version.json")) {
Ok(s) => serde_json::from_str(&s)?,
_ => WebVaultVersion {
version: String::from("Version file missing"),
diff --git a/src/auth.rs b/src/auth.rs
index 34eff5fb..f99fbd39 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -11,7 +11,6 @@ use serde::ser::Serialize;
use crate::{
error::{Error, MapResult},
- util::read_file,
CONFIG,
};
@@ -30,13 +29,13 @@ static JWT_ADMIN_ISSUER: Lazy<String> = Lazy::new(|| format!("{}|admin", CONFIG.
static JWT_SEND_ISSUER: Lazy<String> = Lazy::new(|| format!("{}|send", CONFIG.domain_origin()));
static PRIVATE_RSA_KEY_VEC: Lazy<Vec<u8>> = Lazy::new(|| {
- read_file(&CONFIG.private_rsa_key()).unwrap_or_else(|e| panic!("Error loading private RSA Key.\n{}", e))
+ std::fs::read(&CONFIG.private_rsa_key()).unwrap_or_else(|e| panic!("Error loading private RSA Key.\n{}", e))
});
static PRIVATE_RSA_KEY: Lazy<EncodingKey> = Lazy::new(|| {
EncodingKey::from_rsa_pem(&PRIVATE_RSA_KEY_VEC).unwrap_or_else(|e| panic!("Error decoding private RSA Key.\n{}", e))
});
static PUBLIC_RSA_KEY_VEC: Lazy<Vec<u8>> = Lazy::new(|| {
- read_file(&CONFIG.public_rsa_key()).unwrap_or_else(|e| panic!("Error loading public RSA Key.\n{}", e))
+ std::fs::read(&CONFIG.public_rsa_key()).unwrap_or_else(|e| panic!("Error loading public RSA Key.\n{}", e))
});
static PUBLIC_RSA_KEY: Lazy<DecodingKey> = Lazy::new(|| {
DecodingKey::from_rsa_pem(&PUBLIC_RSA_KEY_VEC).unwrap_or_else(|e| panic!("Error decoding public RSA Key.\n{}", e))
diff --git a/src/config.rs b/src/config.rs
index 09240c36..8cc96f56 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -91,8 +91,7 @@ macro_rules! make_config {
}
fn from_file(path: &str) -> Result<Self, Error> {
- use crate::util::read_file_string;
- let config_str = read_file_string(path)?;
+ let config_str = std::fs::read_to_string(path)?;
serde_json::from_str(&config_str).map_err(Into::into)
}
diff --git a/src/main.rs b/src/main.rs
index 313fe77b..20f40bc5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -328,7 +328,7 @@ fn check_rsa_keys() -> Result<(), crate::error::Error> {
}
if !util::file_exists(&pub_path) {
- let rsa_key = openssl::rsa::Rsa::private_key_from_pem(&util::read_file(&priv_path)?)?;
+ let rsa_key = openssl::rsa::Rsa::private_key_from_pem(&std::fs::read(&priv_path)?)?;
let pub_key = rsa_key.public_key_to_pem()?;
crate::util::write_file(&pub_path, &pub_key)?;
diff --git a/src/util.rs b/src/util.rs
index e00583b6..9bf697ba 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -308,11 +308,6 @@ pub fn file_exists(path: &str) -> bool {
Path::new(path).exists()
}
-pub fn read_file(path: &str) -> IOResult<Vec<u8>> {
- let contents = fs::read(Path::new(path))?;
- Ok(contents)
-}
-
pub fn write_file(path: &str, content: &[u8]) -> Result<(), crate::error::Error> {
use std::io::Write;
let mut f = File::create(path)?;
@@ -321,11 +316,6 @@ pub fn write_file(path: &str, content: &[u8]) -> Result<(), crate::error::Error>
Ok(())
}
-pub fn read_file_string(path: &str) -> IOResult<String> {
- let contents = fs::read_to_string(Path::new(path))?;
- Ok(contents)
-}
-
pub fn delete_file(path: &str) -> IOResult<()> {
let res = fs::remove_file(path);