aboutsummaryrefslogtreecommitdiff
path: root/src/model/k2v/seen.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-01-11 12:27:19 +0100
committerAlex Auvolat <alex@adnab.me>2023-01-11 12:27:19 +0100
commitbba13f40fc2e411347ea83960935b39cedb0a7c4 (patch)
treeaefe6849f34e458ec562b7d8379c52c8fcc037a0 /src/model/k2v/seen.rs
parentba384e61c0951036b0c4fb394011f3498abf67ca (diff)
downloadgarage-bba13f40fc2e411347ea83960935b39cedb0a7c4.tar.gz
garage-bba13f40fc2e411347ea83960935b39cedb0a7c4.zip
Correctly return bad requests when seeh marker is invalid
Diffstat (limited to 'src/model/k2v/seen.rs')
-rw-r--r--src/model/k2v/seen.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/model/k2v/seen.rs b/src/model/k2v/seen.rs
index d2cd54c7..314d0f9e 100644
--- a/src/model/k2v/seen.rs
+++ b/src/model/k2v/seen.rs
@@ -13,8 +13,9 @@ use serde::{Deserialize, Serialize};
use garage_util::data::Uuid;
use garage_util::encode::{nonversioned_decode, nonversioned_encode};
-use garage_util::error::{Error, OkOrMessage};
+use garage_util::error::Error;
+use crate::helper::error::{Error as HelperError, OkOrBadRequest};
use crate::k2v::causality::*;
use crate::k2v::item_table::*;
use crate::k2v::sub::*;
@@ -80,10 +81,15 @@ impl RangeSeenMarker {
Ok(base64::encode(&bytes))
}
- pub fn decode(s: &str) -> Result<Self, Error> {
- let bytes = base64::decode(&s).ok_or_message("invalid base64")?;
- let bytes = zstd::stream::decode_all(&mut &bytes[..])?;
- Ok(nonversioned_decode(&bytes)?)
+ /// Decode from msgpack+zstd+b64 representation, returns None on error.
+ pub fn decode(s: &str) -> Option<Self> {
+ let bytes = base64::decode(&s).ok()?;
+ let bytes = zstd::stream::decode_all(&mut &bytes[..]).ok()?;
+ nonversioned_decode(&bytes).ok()
+ }
+
+ pub fn decode_helper(s: &str) -> Result<Self, HelperError> {
+ Self::decode(s).ok_or_bad_request("Invalid causality token")
}
pub fn is_new_item(&self, item: &K2VItem) -> bool {