This commit is contained in:
Edward Shen 2022-01-02 13:25:00 -08:00
parent f6a9caf653
commit 81604a7e94
Signed by: edward
GPG key ID: 19182661E818369F
4 changed files with 22 additions and 18 deletions

13
src/cache/fs.rs vendored
View file

@ -121,13 +121,16 @@ pub(super) async fn read_file(
// parsed_metadata is either set or unset here. If it's set then we // parsed_metadata is either set or unset here. If it's set then we
// successfully decoded the data; otherwise the file is garbage. // successfully decoded the data; otherwise the file is garbage.
if let Some(reader) = reader { reader.map_or_else(
let stream = CacheStream::Completed(ReaderStream::new(reader)); || {
parsed_metadata.map(|metadata| Ok((stream, maybe_header, metadata)))
} else {
debug!("Reader was invalid, file is corrupt"); debug!("Reader was invalid, file is corrupt");
None None
} },
|reader| {
let stream = CacheStream::Completed(ReaderStream::new(reader));
parsed_metadata.map(|metadata| Ok((stream, maybe_header, metadata)))
},
)
} }
struct EncryptedReader<R> { struct EncryptedReader<R> {

View file

@ -73,7 +73,7 @@ impl<'a> From<(&'a ClientSecret, &Config)> for Request<'a> {
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
#[serde(untagged)] #[serde(untagged)]
pub enum Response { pub enum Response {
Ok(OkResponse), Ok(Box<OkResponse>),
Error(ErrorResponse), Error(ErrorResponse),
} }

View file

@ -3,10 +3,10 @@ use std::sync::atomic::Ordering;
use actix_web::body::BoxBody; use actix_web::body::BoxBody;
use actix_web::error::ErrorNotFound; use actix_web::error::ErrorNotFound;
use actix_web::http::header::{CONTENT_LENGTH, CONTENT_TYPE, LAST_MODIFIED, HeaderValue}; use actix_web::http::header::{HeaderValue, CONTENT_LENGTH, CONTENT_TYPE, LAST_MODIFIED};
use actix_web::web::Path; use actix_web::web::{Data, Path};
use actix_web::HttpResponseBuilder; use actix_web::HttpResponseBuilder;
use actix_web::{get, web::Data, HttpRequest, HttpResponse, Responder}; use actix_web::{get, HttpRequest, HttpResponse, Responder};
use base64::DecodeError; use base64::DecodeError;
use bytes::Bytes; use bytes::Bytes;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};

View file

@ -64,15 +64,16 @@ impl ServerState {
.token_key .token_key
.ok_or(ServerInitError::MissingTokenKey) .ok_or(ServerInitError::MissingTokenKey)
.and_then(|key| { .and_then(|key| {
if let Some(key) = base64::decode(&key) base64::decode(&key)
.ok() .ok()
.and_then(|k| PrecomputedKey::from_slice(&k)) .and_then(|k| PrecomputedKey::from_slice(&k))
{ .map_or_else(
Ok(key) || {
} else {
error!("Failed to parse token key: got {}", key); error!("Failed to parse token key: got {}", key);
Err(ServerInitError::KeyParseError(key)) Err(ServerInitError::KeyParseError(key))
} },
Ok,
)
})?; })?;
PREVIOUSLY_COMPROMISED.store(resp.compromised, Ordering::Release); PREVIOUSLY_COMPROMISED.store(resp.compromised, Ordering::Release);