mirror of
				https://github.com/dani-garcia/vaultwarden.git
				synced 2025-10-31 10:18:19 +02:00 
			
		
		
		
	Macro recursion decrease and other optimizations
- Decreased `recursion_limit` from 512 to 87 Mainly done by optimizing the config macro's. This fixes an issue with the rust-analyzer which doesn't go beyond 128 - Removed Regex for masking sensitive values and replaced it with a map() This is much faster then using a Regex. - Refactored the get_support_json macro's - All items above also lowered the binary size and possibly compile-time - Removed `_conn: DbConn` from several functions, these caused unnecessary database connections for functions who didn't used that at all - Decreased json response for `/plans` - Updated libraries and where needed some code changes This also fixes some rare issues with SMTP https://github.com/lettre/lettre/issues/678 - Using Rust 2021 instead of 2018 - Updated rust nightly
This commit is contained in:
		
							
								
								
									
										17
									
								
								src/util.rs
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								src/util.rs
									
									
									
									
									
								
							| @@ -282,9 +282,9 @@ pub fn delete_file(path: &str) -> IOResult<()> { | ||||
|     res | ||||
| } | ||||
|  | ||||
| const UNITS: [&str; 6] = ["bytes", "KB", "MB", "GB", "TB", "PB"]; | ||||
|  | ||||
| pub fn get_display_size(size: i32) -> String { | ||||
|     const UNITS: [&str; 6] = ["bytes", "KB", "MB", "GB", "TB", "PB"]; | ||||
|  | ||||
|     let mut size: f64 = size.into(); | ||||
|     let mut unit_counter = 0; | ||||
|  | ||||
| @@ -359,10 +359,10 @@ where | ||||
|     try_parse_string(get_env_str_value(key)) | ||||
| } | ||||
|  | ||||
| const TRUE_VALUES: &[&str] = &["true", "t", "yes", "y", "1"]; | ||||
| const FALSE_VALUES: &[&str] = &["false", "f", "no", "n", "0"]; | ||||
|  | ||||
| pub fn get_env_bool(key: &str) -> Option<bool> { | ||||
|     const TRUE_VALUES: &[&str] = &["true", "t", "yes", "y", "1"]; | ||||
|     const FALSE_VALUES: &[&str] = &["false", "f", "no", "n", "0"]; | ||||
|  | ||||
|     match get_env_str_value(key) { | ||||
|         Some(val) if TRUE_VALUES.contains(&val.to_lowercase().as_ref()) => Some(true), | ||||
|         Some(val) if FALSE_VALUES.contains(&val.to_lowercase().as_ref()) => Some(false), | ||||
| @@ -375,7 +375,6 @@ pub fn get_env_bool(key: &str) -> Option<bool> { | ||||
| // | ||||
|  | ||||
| use chrono::{DateTime, Local, NaiveDateTime, TimeZone}; | ||||
| use chrono_tz::Tz; | ||||
|  | ||||
| /// Formats a UTC-offset `NaiveDateTime` in the format used by Bitwarden API | ||||
| /// responses with "date" fields (`CreationDate`, `RevisionDate`, etc.). | ||||
| @@ -393,7 +392,7 @@ pub fn format_datetime_local(dt: &DateTime<Local>, fmt: &str) -> String { | ||||
|     // Try parsing the `TZ` environment variable to enable formatting `%Z` as | ||||
|     // a time zone abbreviation. | ||||
|     if let Ok(tz) = env::var("TZ") { | ||||
|         if let Ok(tz) = tz.parse::<Tz>() { | ||||
|         if let Ok(tz) = tz.parse::<chrono_tz::Tz>() { | ||||
|             return dt.with_timezone(&tz).format(fmt).to_string(); | ||||
|         } | ||||
|     } | ||||
| @@ -442,7 +441,7 @@ use serde_json::{self, Value}; | ||||
|  | ||||
| pub type JsonMap = serde_json::Map<String, Value>; | ||||
|  | ||||
| #[derive(PartialEq, Serialize, Deserialize)] | ||||
| #[derive(Serialize, Deserialize)] | ||||
| pub struct UpCase<T: DeserializeOwned> { | ||||
|     #[serde(deserialize_with = "upcase_deserialize")] | ||||
|     #[serde(flatten)] | ||||
| @@ -517,6 +516,8 @@ fn upcase_value(value: Value) -> Value { | ||||
|     } | ||||
| } | ||||
|  | ||||
| // Inner function to handle some speciale case for the 'ssn' key. | ||||
| // This key is part of the Identity Cipher (Social Security Number) | ||||
| fn _process_key(key: &str) -> String { | ||||
|     match key.to_lowercase().as_ref() { | ||||
|         "ssn" => "SSN".into(), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user