diff --git a/Cargo.lock b/Cargo.lock index bc268bb..8fc2129 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -279,6 +279,7 @@ dependencies = [ "log", "mime-sniffer", "mime2ext", + "negentropy", "parking_lot", "pocket-db", "pocket-types", @@ -1147,6 +1148,12 @@ dependencies = [ "memmap2", ] +[[package]] +name = "negentropy" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a88da9dd148bbcdce323dd6ac47d369b4769d4a3b78c6c52389b9269f77932" + [[package]] name = "nom" version = "7.1.3" diff --git a/Cargo.toml b/Cargo.toml index 6550e2a..6252ea0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ lazy_static = "1.5" log = "0.4" mime-sniffer = "0.1" mime2ext = "0.1" +negentropy = "0.4" pocket-types = { git = "https://github.com/mikedilger/pocket", branch = "master" } pocket-db = { git = "https://github.com/mikedilger/pocket", branch = "master" } parking_lot = "0.12" diff --git a/src/error.rs b/src/error.rs index fd05261..c48302e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -104,6 +104,9 @@ pub enum ChorusError { // Missing Table MissingTable(&'static str), + // Negentropy error + Negentropy(negentropy::Error), + // Non-ASCII HTTP header value NonAsciiHttpHeaderValue(http::header::ToStrError), @@ -209,6 +212,7 @@ impl std::fmt::Display for ChorusError { ChorusError::Io(e) => write!(f, "{e}"), ChorusError::ManagementAuthFailure(s) => write!(f, "Authorization failure: {s}"), ChorusError::MissingTable(t) => write!(f, "Missing table: {t}"), + ChorusError::Negentropy(e) => write!(f, "Negentropy: {e}"), ChorusError::NonAsciiHttpHeaderValue(e) => { write!(f, "Non ASCII HTTP header value: {e}") } @@ -308,6 +312,7 @@ impl ChorusError { ChorusError::Io(_) => 0.0, ChorusError::ManagementAuthFailure(_) => 0.0, ChorusError::MissingTable(_) => 0.0, + ChorusError::Negentropy(_) => 0.1, ChorusError::NonAsciiHttpHeaderValue(_) => 0.2, ChorusError::NoPrivateKey => 0.0, ChorusError::NotImplemented => 0.0, @@ -583,6 +588,16 @@ impl From for Error { } } +impl From for Error { + #[track_caller] + fn from(e: negentropy::Error) -> Error { + Error { + inner: ChorusError::Negentropy(e), + location: std::panic::Location::caller(), + } + } +} + impl From for Error { fn from(_: Infallible) -> Self { panic!("INFALLIBLE")