From 0fca3a944a27a548a8d21508bfb67ba7828ab94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Fri, 26 Apr 2024 00:52:10 +0000 Subject: [PATCH] base64 0.22, serde_with 3, url 2 url v2 no longer exports percent_encoding, add percent-encoding v2 as explicit dependency percent-encoding v2 no longer includes predefined encoding sets --- google-apis-common/Cargo.toml | 9 +++++---- google-apis-common/src/serde.rs | 11 +++++++---- google-apis-common/src/url.rs | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/google-apis-common/Cargo.toml b/google-apis-common/Cargo.toml index f94bb9b42aa..b3bf6b15928 100644 --- a/google-apis-common/Cargo.toml +++ b/google-apis-common/Cargo.toml @@ -18,15 +18,16 @@ doctest = false [dependencies] mime = "^ 0.3" serde = { version = "^ 1.0", features = ["derive"] } -serde_with = "2.0.1" +serde_with = "3.0" serde_json = "^ 1.0" -base64 = "0.13.0" +base64 = "0.22" chrono = { version = "0.4.35", default-features = false, features = ["clock", "serde"] } -url = "= 1.7" +url = "2.0" +percent-encoding = "2.0" yup-oauth2 = { version = "9", optional = true } -itertools = "^ 0.10" +itertools = "^ 0.12" hyper = { version = "^ 0.14", features = ["client", "http2"] } http = "^0.2" tokio = { version = "^1.0", features = ["time"] } diff --git a/google-apis-common/src/serde.rs b/google-apis-common/src/serde.rs index d645658d955..622a60a215e 100644 --- a/google-apis-common/src/serde.rs +++ b/google-apis-common/src/serde.rs @@ -144,6 +144,7 @@ pub mod duration { } pub mod standard_base64 { + use base64::Engine as _; use serde::{Deserialize, Deserializer, Serializer}; use serde_with::{DeserializeAs, SerializeAs}; use std::borrow::Cow; @@ -151,7 +152,7 @@ pub mod standard_base64 { pub struct Wrapper; pub fn to_string(bytes: &Vec) -> String { - base64::encode_config(bytes, base64::STANDARD) + base64::prelude::BASE64_STANDARD.encode(bytes) } impl SerializeAs> for Wrapper { @@ -169,12 +170,13 @@ pub mod standard_base64 { D: Deserializer<'de>, { let s: Cow = Deserialize::deserialize(deserializer)?; - base64::decode_config(s.as_ref(), base64::STANDARD).map_err(serde::de::Error::custom) + base64::prelude::BASE64_STANDARD.decode(s.as_ref()).map_err(serde::de::Error::custom) } } } pub mod urlsafe_base64 { + use base64::Engine as _; use serde::{Deserialize, Deserializer, Serializer}; use serde_with::{DeserializeAs, SerializeAs}; use std::borrow::Cow; @@ -182,7 +184,7 @@ pub mod urlsafe_base64 { pub struct Wrapper; pub fn to_string(bytes: &Vec) -> String { - base64::encode_config(bytes, base64::URL_SAFE) + base64::prelude::BASE64_URL_SAFE.encode(bytes) } impl SerializeAs> for Wrapper { @@ -200,7 +202,7 @@ pub mod urlsafe_base64 { D: Deserializer<'de>, { let s: Cow = Deserialize::deserialize(deserializer)?; - base64::decode_config(s.as_ref(), base64::URL_SAFE).map_err(serde::de::Error::custom) + base64::prelude::BASE64_URL_SAFE.decode(s.as_ref()).map_err(serde::de::Error::custom) } } } @@ -212,6 +214,7 @@ pub fn datetime_to_string(datetime: &chrono::DateTime) -> S #[cfg(test)] mod test { use super::{duration, standard_base64, urlsafe_base64}; + use base64::Engine as _; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, DisplayFromStr}; diff --git a/google-apis-common/src/url.rs b/google-apis-common/src/url.rs index e175c3aa496..3da0b3c7bcf 100644 --- a/google-apis-common/src/url.rs +++ b/google-apis-common/src/url.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use ::url::percent_encoding::{percent_encode, DEFAULT_ENCODE_SET}; +use ::percent_encoding::{percent_encode, AsciiSet, CONTROLS}; use ::url::Url; pub struct Params<'a> { @@ -40,6 +40,7 @@ impl<'a> Params<'a> { from: &str, url_encode: bool, ) -> String { + const DEFAULT_ENCODE_SET: &AsciiSet = &CONTROLS.add(b' ').add(b'"').add(b'#').add(b'<').add(b'>').add(b'`').add(b'?').add(b'{').add(b'}'); if url_encode { let mut replace_with: Cow = self.get(param).unwrap_or_default().into(); if from.as_bytes()[1] == b'+' {