diff --git a/src/cache/fs.rs b/src/cache/fs.rs index 62f592f..509d9f2 100644 --- a/src/cache/fs.rs +++ b/src/cache/fs.rs @@ -121,13 +121,16 @@ pub(super) async fn read_file( // parsed_metadata is either set or unset here. If it's set then we // successfully decoded the data; otherwise the file is garbage. - if let Some(reader) = reader { - let stream = CacheStream::Completed(ReaderStream::new(reader)); - parsed_metadata.map(|metadata| Ok((stream, maybe_header, metadata))) - } else { - debug!("Reader was invalid, file is corrupt"); - None - } + reader.map_or_else( + || { + debug!("Reader was invalid, file is corrupt"); + None + }, + |reader| { + let stream = CacheStream::Completed(ReaderStream::new(reader)); + parsed_metadata.map(|metadata| Ok((stream, maybe_header, metadata))) + }, + ) } struct EncryptedReader { diff --git a/src/ping.rs b/src/ping.rs index 85f4900..f23430b 100644 --- a/src/ping.rs +++ b/src/ping.rs @@ -73,7 +73,7 @@ impl<'a> From<(&'a ClientSecret, &Config)> for Request<'a> { #[derive(Deserialize, Debug)] #[serde(untagged)] pub enum Response { - Ok(OkResponse), + Ok(Box), Error(ErrorResponse), } diff --git a/src/routes.rs b/src/routes.rs index 84acff9..e862efd 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -3,10 +3,10 @@ use std::sync::atomic::Ordering; use actix_web::body::BoxBody; use actix_web::error::ErrorNotFound; -use actix_web::http::header::{CONTENT_LENGTH, CONTENT_TYPE, LAST_MODIFIED, HeaderValue}; -use actix_web::web::Path; +use actix_web::http::header::{HeaderValue, CONTENT_LENGTH, CONTENT_TYPE, LAST_MODIFIED}; +use actix_web::web::{Data, Path}; use actix_web::HttpResponseBuilder; -use actix_web::{get, web::Data, HttpRequest, HttpResponse, Responder}; +use actix_web::{get, HttpRequest, HttpResponse, Responder}; use base64::DecodeError; use bytes::Bytes; use chrono::{DateTime, Utc}; diff --git a/src/state.rs b/src/state.rs index b540cc2..aa11e0e 100644 --- a/src/state.rs +++ b/src/state.rs @@ -64,15 +64,16 @@ impl ServerState { .token_key .ok_or(ServerInitError::MissingTokenKey) .and_then(|key| { - if let Some(key) = base64::decode(&key) + base64::decode(&key) .ok() .and_then(|k| PrecomputedKey::from_slice(&k)) - { - Ok(key) - } else { - error!("Failed to parse token key: got {}", key); - Err(ServerInitError::KeyParseError(key)) - } + .map_or_else( + || { + error!("Failed to parse token key: got {}", key); + Err(ServerInitError::KeyParseError(key)) + }, + Ok, + ) })?; PREVIOUSLY_COMPROMISED.store(resp.compromised, Ordering::Release);