Skip to content

Commit 6ad908c

Browse files
Bump base64 from 0.13.1 to 0.21.2 (#805)
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent b3eb660 commit 6ad908c

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ahash = "0.8.0"
4040
url = "2.3.1"
4141
# idna is already required by url, added here to be explicit
4242
idna = "0.4.0"
43-
base64 = "0.13.1"
43+
base64 = "0.21.2"
4444
num-bigint = "0.4.3"
4545
python3-dll-a = "0.2.7"
4646

src/serializers/config.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::borrow::Cow;
22
use std::str::{from_utf8, FromStr, Utf8Error};
33

4+
use base64::Engine;
45
use pyo3::prelude::*;
56
use pyo3::types::{PyDelta, PyDict};
67
use pyo3::{intern, PyNativeType};
@@ -119,20 +120,21 @@ impl TimedeltaMode {
119120
}
120121

121122
#[derive(Default, Debug, Clone)]
122-
pub(crate) struct BytesMode {
123-
base64_config: Option<base64::Config>,
123+
pub(crate) enum BytesMode {
124+
#[default]
125+
Utf8,
126+
Base64,
124127
}
125128

126129
impl FromStr for BytesMode {
127130
type Err = PyErr;
128131

129132
fn from_str(s: &str) -> Result<Self, Self::Err> {
130-
let base64_config = match s {
131-
"utf8" => None,
132-
"base64" => Some(base64::Config::new(base64::CharacterSet::UrlSafe, true)),
133-
s => return py_schema_err!("Invalid bytes serialization mode: `{}`, expected `utf8` or `base64`", s),
134-
};
135-
Ok(Self { base64_config })
133+
match s {
134+
"utf8" => Ok(Self::Utf8),
135+
"base64" => Ok(Self::Base64),
136+
s => py_schema_err!("Invalid bytes serialization mode: `{}`, expected `utf8` or `base64`", s),
137+
}
136138
}
137139
}
138140

@@ -146,23 +148,21 @@ impl BytesMode {
146148
}
147149

148150
pub fn bytes_to_string<'py>(&self, py: Python, bytes: &'py [u8]) -> PyResult<Cow<'py, str>> {
149-
if let Some(config) = self.base64_config {
150-
Ok(Cow::Owned(base64::encode_config(bytes, config)))
151-
} else {
152-
from_utf8(bytes)
151+
match self {
152+
Self::Utf8 => from_utf8(bytes)
153153
.map_err(|err| utf8_py_error(py, err, bytes))
154-
.map(Cow::Borrowed)
154+
.map(Cow::Borrowed),
155+
Self::Base64 => Ok(Cow::Owned(base64::engine::general_purpose::URL_SAFE.encode(bytes))),
155156
}
156157
}
157158

158159
pub fn serialize_bytes<S: serde::ser::Serializer>(&self, bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error> {
159-
if let Some(config) = self.base64_config {
160-
serializer.serialize_str(&base64::encode_config(bytes, config))
161-
} else {
162-
match from_utf8(bytes) {
160+
match self {
161+
Self::Utf8 => match from_utf8(bytes) {
163162
Ok(s) => serializer.serialize_str(s),
164163
Err(e) => Err(Error::custom(e.to_string())),
165-
}
164+
},
165+
Self::Base64 => serializer.serialize_str(&base64::engine::general_purpose::URL_SAFE.encode(bytes)),
166166
}
167167
}
168168
}

0 commit comments

Comments
 (0)