From e4f955d672af99d1bf25e6a0bb038d116f8bca0c Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 16 May 2023 18:34:46 +0200 Subject: fix base64 uses --- src/k2v-client/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/k2v-client/lib.rs') diff --git a/src/k2v-client/lib.rs b/src/k2v-client/lib.rs index ca52d0cf..548838f8 100644 --- a/src/k2v-client/lib.rs +++ b/src/k2v-client/lib.rs @@ -1,6 +1,7 @@ use std::collections::BTreeMap; use std::time::Duration; +use base64::prelude::*; use http::header::{ACCEPT, CONTENT_LENGTH, CONTENT_TYPE}; use http::status::StatusCode; use http::HeaderMap; @@ -375,7 +376,7 @@ impl K2vClient { .unwrap_or_default(); let err_body_str = std::str::from_utf8(&err_body) .map(String::from) - .unwrap_or_else(|_| base64::encode(&err_body)); + .unwrap_or_else(|_| BASE64_STANDARD.encode(&err_body)); if s.is_client_error() || s.is_server_error() { error!("Error response {}: {}", res.status, err_body_str); @@ -408,7 +409,7 @@ impl K2vClient { "Response body: {}", std::str::from_utf8(&body) .map(String::from) - .unwrap_or_else(|_| base64::encode(&body)) + .unwrap_or_else(|_| BASE64_STANDARD.encode(&body)) ); Ok(Response { @@ -483,7 +484,7 @@ impl<'de> Deserialize<'de> for K2vValue { let val: Option<&str> = Option::deserialize(d)?; Ok(match val { Some(s) => { - K2vValue::Value(base64::decode(s).map_err(|_| DeError::custom("invalid base64"))?) + K2vValue::Value(BASE64_STANDARD.decode(s).map_err(|_| DeError::custom("invalid base64"))?) } None => K2vValue::Tombstone, }) @@ -498,7 +499,7 @@ impl Serialize for K2vValue { match self { K2vValue::Tombstone => serializer.serialize_none(), K2vValue::Value(v) => { - let b64 = base64::encode(v); + let b64 = BASE64_STANDARD.encode(v); serializer.serialize_str(&b64) } } -- cgit v1.2.3 From 16f2a32bb78cdc0d9cee9806c04065af845d0dff Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 16 May 2023 18:40:27 +0200 Subject: cargo fmt --- src/k2v-client/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/k2v-client/lib.rs') diff --git a/src/k2v-client/lib.rs b/src/k2v-client/lib.rs index 548838f8..3d1b5461 100644 --- a/src/k2v-client/lib.rs +++ b/src/k2v-client/lib.rs @@ -483,9 +483,11 @@ impl<'de> Deserialize<'de> for K2vValue { { let val: Option<&str> = Option::deserialize(d)?; Ok(match val { - Some(s) => { - K2vValue::Value(BASE64_STANDARD.decode(s).map_err(|_| DeError::custom("invalid base64"))?) - } + Some(s) => K2vValue::Value( + BASE64_STANDARD + .decode(s) + .map_err(|_| DeError::custom("invalid base64"))?, + ), None => K2vValue::Tombstone, }) } -- cgit v1.2.3