Skip to content

Commit

Permalink
Base64 decoding accepts standard or url-safe.
Browse files Browse the repository at this point in the history
  • Loading branch information
dantreiman committed Jun 11, 2024
1 parent 279a0a5 commit d659486
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions google-apis-common/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ pub mod standard_base64 {
D: Deserializer<'de>,
{
let s: Cow<str> = Deserialize::deserialize(deserializer)?;
base64::prelude::BASE64_STANDARD.decode(s.as_ref()).map_err(serde::de::Error::custom)
match base64::prelude::BASE64_STANDARD.decode(s.as_ref()) {
Ok(decoded) => Ok(decoded),
Err(first_err) => match general_purpose::URL_SAFE.decode(s.as_ref()) {
Ok(decoded) => Ok(decoded),
Err(_) => Err(serde::de::Error::custom(first_err))
}
}
}
}
}
Expand Down Expand Up @@ -202,7 +208,13 @@ pub mod urlsafe_base64 {
D: Deserializer<'de>,
{
let s: Cow<str> = Deserialize::deserialize(deserializer)?;
base64::prelude::BASE64_URL_SAFE.decode(s.as_ref()).map_err(serde::de::Error::custom)
match base64::prelude::URL_SAFE.decode(s.as_ref()) {
Ok(decoded) => Ok(decoded),
Err(first_err) => match general_purpose::URL_STANDARD.decode(s.as_ref()) {
Ok(decoded) => Ok(decoded),
Err(_) => Err(serde::de::Error::custom(first_err))
}
}
}
}
}
Expand Down

0 comments on commit d659486

Please sign in to comment.