vw_small

Hardened fork of Vaultwarden (https://github.com/dani-garcia/vaultwarden) with fewer features.
git clone https://git.philomathiclife.com/repos/vw_small
Log | Files | Refs | README

commit c9376e312688b7cb711792e6be3da195c4a8070c
parent 7cbcad0e389d6017b941e00051621010066bf796
Author: Daniel GarcĂ­a <dani-garcia@users.noreply.github.com>
Date:   Fri, 15 Jul 2022 19:13:26 +0200

Remove read_file and read_file_string and replace them with the std alternatives

Diffstat:
Msrc/api/admin.rs | 5++---
Msrc/auth.rs | 5++---
Msrc/config.rs | 3+--
Msrc/main.rs | 2+-
Msrc/util.rs | 10----------
5 files changed, 6 insertions(+), 19 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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);