From 3b9315c22e74c6f96024bf235429f0ba90212b96 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 3 Oct 2023 12:52:54 +0200 Subject: [PATCH] Change base64 crate to simple-base64 crate Standard base64 encode/decode functions have been deprecated and it's clear that the maintainer doesn't care about ergonomics of using the crate[1], so I've forked the crate to be able to get back to a simple format of calling the decode/encode functions. --- Cargo.lock | 12 +++++++++--- Cargo.toml | 2 +- crates/cli/Cargo.toml | 2 +- crates/cli/src/util.rs | 3 +-- crates/core/Cargo.toml | 2 +- crates/core/src/client/message_handlers.rs | 8 ++------ crates/core/src/client/messages.rs | 3 +-- crates/core/src/host/module_host.rs | 3 +-- crates/sdk/Cargo.toml | 2 +- crates/sdk/src/websocket.rs | 4 +--- 10 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e7d3e7bc03..8f35711db4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4062,6 +4062,12 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf" +[[package]] +name = "simple-base64" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e124c5aa3994a402e8f10d7c4d1241298277d53dad230d82b97d56b0ac6eca5" + [[package]] name = "simple_asn1" version = "0.6.2" @@ -4220,7 +4226,6 @@ name = "spacetimedb-cli" version = "0.6.1" dependencies = [ "anyhow", - "base64 0.21.2", "cargo_metadata", "clap 4.3.10", "colored", @@ -4237,6 +4242,7 @@ dependencies = [ "rustyline", "serde", "serde_json", + "simple-base64", "slab", "spacetimedb-core", "spacetimedb-lib", @@ -4299,7 +4305,6 @@ dependencies = [ "anyhow", "async-trait", "backtrace", - "base64 0.21.2", "bytes", "bytestring", "clap 4.3.10", @@ -4343,6 +4348,7 @@ dependencies = [ "serde_path_to_error", "serde_with", "sha1", + "simple-base64", "slab", "sled", "spacetimedb-client-api-messages", @@ -4431,7 +4437,6 @@ version = "0.6.1" dependencies = [ "anyhow", "anymap", - "base64 0.21.2", "cursive", "futures", "futures-channel", @@ -4443,6 +4448,7 @@ dependencies = [ "log", "prost", "rand 0.8.5", + "simple-base64", "spacetimedb-client-api-messages", "spacetimedb-lib", "spacetimedb-sats", diff --git a/Cargo.toml b/Cargo.toml index f9586c5635..9b52615ecb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,7 +66,7 @@ async-trait = "0.1.68" axum = "0.6" arrayvec = "0.7.2" backtrace = "0.3.66" -base64 = "0.21.2" +simple-base64 = "0.23.0" bitflags = "2.3.3" byte-unit = "4.0.18" bytes = "1.2.1" diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index de6f86bed1..0472b55b8c 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -22,7 +22,7 @@ spacetimedb-lib = { path = "../lib", version = "0.6.1", features = ["cli"] } spacetimedb-standalone = { path = "../standalone", version = "0.6.1", optional = true } anyhow.workspace = true -base64.workspace = true +simple-base64.workspace = true cargo_metadata.workspace = true clap = {workspace = true, features = ["derive", "env", "string"]} colored.workspace = true diff --git a/crates/cli/src/util.rs b/crates/cli/src/util.rs index 0d35e792cc..60f44a2a6d 100644 --- a/crates/cli/src/util.rs +++ b/crates/cli/src/util.rs @@ -1,5 +1,4 @@ use anyhow::Context; -use base64::{engine::general_purpose::STANDARD as BASE_64_STD, Engine as _}; use reqwest::RequestBuilder; use serde::Deserialize; use spacetimedb_lib::name::{is_address, DnsLookupResponse, RegisterTldResult, ReverseDNSResponse}; @@ -278,7 +277,7 @@ pub async fn get_auth_header( auth_header.push_str( format!( "Basic {}", - BASE_64_STD.encode(format!("token:{}", identity_config.token)) + simple_base64::encode(format!("token:{}", identity_config.token)) ) .as_str(), ); diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 703f0b3a55..1205bde135 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -26,7 +26,7 @@ spacetimedb-client-api-messages = { path = "../client-api-messages", version = " anyhow.workspace = true async-trait.workspace = true backtrace.workspace = true -base64.workspace = true +simple-base64.workspace = true bytes.workspace = true bytestring.workspace = true clap.workspace = true diff --git a/crates/core/src/client/message_handlers.rs b/crates/core/src/client/message_handlers.rs index edc394f799..9f02fe1760 100644 --- a/crates/core/src/client/message_handlers.rs +++ b/crates/core/src/client/message_handlers.rs @@ -5,7 +5,6 @@ use crate::host::{EnergyDiff, ReducerArgs, Timestamp}; use crate::identity::Identity; use crate::protobuf::client_api::{message, FunctionCall, Message, Subscribe}; use crate::worker_metrics::{WEBSOCKET_REQUESTS, WEBSOCKET_REQUEST_MSG_SIZE}; -use base64::Engine; use bytes::Bytes; use bytestring::ByteString; use prost::Message as _; @@ -23,7 +22,7 @@ pub enum MessageHandleError { #[error(transparent)] TextDecode(#[from] serde_json::Error), #[error(transparent)] - Base64Decode(#[from] base64::DecodeError), + Base64Decode(#[from] simple_base64::DecodeError), #[error(transparent)] Execution(#[from] MessageExecutionError), @@ -104,10 +103,7 @@ async fn handle_text(client: &ClientConnection, message: String) -> Result<(), M query_string: ref query, message_id, } => { - let _ = std::mem::replace( - &mut message_id_, - base64::engine::general_purpose::STANDARD.decode(&message_id[..])?, - ); + let _ = std::mem::replace(&mut message_id_, simple_base64::decode(&message_id[..])?); DecodedMessage::OneOffQuery { query_string: &query[..], message_id: &message_id_[..], diff --git a/crates/core/src/client/messages.rs b/crates/core/src/client/messages.rs index f09bfdd019..9a8f977ec8 100644 --- a/crates/core/src/client/messages.rs +++ b/crates/core/src/client/messages.rs @@ -1,4 +1,3 @@ -use base64::Engine; use prost::Message as _; use spacetimedb_client_api_messages::client_api::{OneOffQueryResponse, OneOffTable}; use spacetimedb_lib::{relation::MemTable, Address}; @@ -198,7 +197,7 @@ pub struct OneOffQueryResponseMessage { impl ServerMessage for OneOffQueryResponseMessage { fn serialize_text(self) -> MessageJson { MessageJson::OneOffQueryResponse(OneOffQueryResponseJson { - message_id_base64: base64::engine::general_purpose::STANDARD.encode(self.message_id), + message_id_base64: simple_base64::encode(self.message_id), error: self.error, result: self .results diff --git a/crates/core/src/host/module_host.rs b/crates/core/src/host/module_host.rs index 33e1318bd2..d264ef43b0 100644 --- a/crates/core/src/host/module_host.rs +++ b/crates/core/src/host/module_host.rs @@ -12,7 +12,6 @@ use crate::protobuf::client_api::{table_row_operation, SubscriptionUpdate, Table use crate::subscription::module_subscription_actor::ModuleSubscriptionManager; use crate::util::lending_pool::{Closed, LendingPool, LentResource, PoolClosed}; use crate::util::notify_once::NotifyOnce; -use base64::{engine::general_purpose::STANDARD as BASE_64_STD, Engine as _}; use futures::{Future, FutureExt}; use indexmap::IndexMap; use spacetimedb_lib::relation::MemTable; @@ -128,7 +127,7 @@ impl DatabaseUpdate { .ops .into_iter() .map(|op| { - let row_pk = BASE_64_STD.encode(&op.row_pk); + let row_pk = simple_base64::encode(&op.row_pk); TableRowOperationJson { op: if op.op_type == 1 { "insert".into() diff --git a/crates/sdk/Cargo.toml b/crates/sdk/Cargo.toml index 335d784ad2..98aff2849a 100644 --- a/crates/sdk/Cargo.toml +++ b/crates/sdk/Cargo.toml @@ -14,7 +14,7 @@ spacetimedb-client-api-messages = { path = "../client-api-messages", version = " anyhow.workspace = true anymap.workspace = true -base64.workspace = true +simple-base64.workspace = true futures.workspace = true futures-channel.workspace = true home.workspace = true diff --git a/crates/sdk/src/websocket.rs b/crates/sdk/src/websocket.rs index 14aa397798..898045135c 100644 --- a/crates/sdk/src/websocket.rs +++ b/crates/sdk/src/websocket.rs @@ -107,10 +107,8 @@ const AUTH_HEADER_KEY: &str = "Authorization"; fn request_insert_auth_header(req: &mut http::Request<()>, credentials: Option<&Credentials>) { // TODO: figure out how the token is supposed to be encoded in the request if let Some(Credentials { token, .. }) = credentials { - use base64::Engine; - let auth_bytes = format!("token:{}", token.string); - let encoded = base64::prelude::BASE64_STANDARD.encode(auth_bytes); + let encoded = simple_base64::encode(auth_bytes); let auth_header_val = format!("Basic {}", encoded); request_add_header( req,