Skip to content

Commit

Permalink
Replace base64 with data-encoding (#34)
Browse files Browse the repository at this point in the history
* Replace base64 with data-encoding

* Update CHANGELOG
  • Loading branch information
Jake-Shadle authored Oct 4, 2023
1 parent 0038db3 commit 531fe3d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- next-header -->
## [Unreleased] - ReleaseDate
### Changed
- [PR#34](https://github.com/EmbarkStudios/discord-sdk/pull/34) replaced `base64` with `data-encoding`.

## [0.3.4] - 2023-03-31
### Fixed
- [PR#30](https://github.com/EmbarkStudios/discord-sdk/pull/30) fixed a bug with asset key validation added in [PR#26](https://github.com/EmbarkStudios/discord-sdk/pull/26). Thanks [@winrg](https://github.com/winrg)!
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
# The actual library crate
"sdk",
Expand Down
2 changes: 1 addition & 1 deletion examples/repl/examples/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ async fn main() -> Result<(), anyhow::Error> {
}
};

match Cmd::try_parse_from(std::iter::once("repl".to_owned()).chain(split.into_iter())) {
match Cmd::try_parse_from(std::iter::once("repl".to_owned()).chain(split)) {
Ok(cmd) => {
if let Commands::Exit = &cmd.cmd {
break;
Expand Down
4 changes: 2 additions & 2 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ anyhow = "1.0"
async-trait = "0.1"
# Lobby messages can be an arbitrary binary blob which needs to be encoded
# in base64
base64 = "0.21"
data-encoding = "2.4"
bitflags = "2.0"
crossbeam-channel = "0.5"
num-traits = "0.2"
Expand Down Expand Up @@ -62,7 +62,7 @@ app_dirs2 = "2.3"

[target.'cfg(target_os = "windows")'.dependencies]
# We need to read and modify the registry when doing application registration
winreg = "0.11"
winreg = "0.51"

[dev-dependencies]
# So tests can print out tracing
Expand Down
8 changes: 3 additions & 5 deletions sdk/src/lobby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ impl Serialize for LobbyMessage {
match self {
Self::Binary(bin) => {
let mut data = String::from("data:text/plain;base64,");
use base64::Engine;
base64::engine::general_purpose::STANDARD_NO_PAD.encode_string(bin, &mut data);
data_encoding::BASE64_NOPAD.encode_append(bin, &mut data);

serializer.serialize_str(&data)
}
Expand Down Expand Up @@ -323,9 +322,8 @@ impl<'de> Deserialize<'de> for LobbyMessage {
E: de::Error,
{
let msg = if let Some(encoded) = v.strip_prefix("data:text/plain;base64,") {
use base64::Engine;
let bin = base64::engine::general_purpose::STANDARD_NO_PAD
.decode(encoded)
let bin = data_encoding::BASE64_NOPAD
.decode(encoded.as_bytes())
.map_err(de::Error::custom)?;
LobbyMessage::Binary(bin)
} else {
Expand Down

0 comments on commit 531fe3d

Please sign in to comment.