Upgrade base64 to v0.22 (#15304)

This PR upgrades the `base64` dependency to v0.22.

Supersedes #15300.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-07-26 17:40:38 -04:00 committed by GitHub
parent 03ebbcbef6
commit e423f03ba6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 16 additions and 20 deletions

12
Cargo.lock generated
View File

@ -1484,12 +1484,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce"
[[package]]
name = "base64"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.21.7" version = "0.21.7"
@ -2454,7 +2448,7 @@ dependencies = [
"aws-sdk-s3", "aws-sdk-s3",
"axum", "axum",
"axum-extra", "axum-extra",
"base64 0.13.1", "base64 0.22.0",
"call", "call",
"channel", "channel",
"chrono", "chrono",
@ -8708,7 +8702,7 @@ dependencies = [
"alacritty_terminal 0.23.0", "alacritty_terminal 0.23.0",
"anyhow", "anyhow",
"async-dispatcher", "async-dispatcher",
"base64 0.13.1", "base64 0.22.0",
"client", "client",
"collections", "collections",
"command_palette_hooks", "command_palette_hooks",
@ -8932,7 +8926,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-tungstenite", "async-tungstenite",
"base64 0.13.1", "base64 0.22.0",
"chrono", "chrono",
"collections", "collections",
"env_logger", "env_logger",

View File

@ -316,7 +316,7 @@ async-trait = "0.1"
async-tungstenite = "0.23" async-tungstenite = "0.23"
async-watch = "0.3.1" async-watch = "0.3.1"
async_zip = { version = "0.0.17", features = ["deflate", "deflate64"] } async_zip = { version = "0.0.17", features = ["deflate", "deflate64"] }
base64 = "0.13" base64 = "0.22"
bitflags = "2.6.0" bitflags = "2.6.0"
blade-graphics = { git = "https://github.com/zed-industries/blade", rev = "7e497c534d5d4a30c18d9eb182cf39eaf0aaa25e" } blade-graphics = { git = "https://github.com/zed-industries/blade", rev = "7e497c534d5d4a30c18d9eb182cf39eaf0aaa25e" }
blade-macros = { git = "https://github.com/zed-industries/blade", rev = "7e497c534d5d4a30c18d9eb182cf39eaf0aaa25e" } blade-macros = { git = "https://github.com/zed-industries/blade", rev = "7e497c534d5d4a30c18d9eb182cf39eaf0aaa25e" }

View File

@ -9,6 +9,7 @@ use axum::{
middleware::Next, middleware::Next,
response::IntoResponse, response::IntoResponse,
}; };
use base64::prelude::*;
use prometheus::{exponential_buckets, register_histogram, Histogram}; use prometheus::{exponential_buckets, register_histogram, Histogram};
pub use rpc::auth::random_token; pub use rpc::auth::random_token;
use scrypt::{ use scrypt::{
@ -155,10 +156,7 @@ pub async fn create_access_token(
/// protection. /// protection.
pub fn hash_access_token(token: &str) -> String { pub fn hash_access_token(token: &str) -> String {
let digest = sha2::Sha256::digest(token); let digest = sha2::Sha256::digest(token);
format!( format!("$sha256${}", BASE64_URL_SAFE.encode(digest))
"$sha256${}",
base64::encode_config(digest, base64::URL_SAFE)
)
} }
/// Encrypts the given access token with the given public key to avoid leaking it on the way /// Encrypts the given access token with the given public key to avoid leaking it on the way

View File

@ -3,6 +3,7 @@ use std::time::Duration;
use crate::stdio::TerminalOutput; use crate::stdio::TerminalOutput;
use anyhow::Result; use anyhow::Result;
use base64::prelude::*;
use gpui::{ use gpui::{
img, percentage, Animation, AnimationExt, AnyElement, FontWeight, ImageData, Render, TextRun, img, percentage, Animation, AnimationExt, AnyElement, FontWeight, ImageData, Render, TextRun,
Transformation, View, Transformation, View,
@ -63,7 +64,7 @@ impl ImageView {
} }
fn from(base64_encoded_data: &str) -> Result<Self> { fn from(base64_encoded_data: &str) -> Result<Self> {
let bytes = base64::decode(base64_encoded_data)?; let bytes = BASE64_STANDARD.decode(base64_encoded_data)?;
let format = image::guess_format(&bytes)?; let format = image::guess_format(&bytes)?;
let mut data = image::load_from_memory_with_format(&bytes, format)?.into_rgba8(); let mut data = image::load_from_memory_with_format(&bytes, format)?.into_rgba8();

View File

@ -1,4 +1,5 @@
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use base64::prelude::*;
use rand::{thread_rng, Rng as _}; use rand::{thread_rng, Rng as _};
use rsa::pkcs1::{DecodeRsaPublicKey, EncodeRsaPublicKey}; use rsa::pkcs1::{DecodeRsaPublicKey, EncodeRsaPublicKey};
use rsa::traits::PaddingScheme; use rsa::traits::PaddingScheme;
@ -44,7 +45,7 @@ pub fn random_token() -> String {
for byte in token_bytes.iter_mut() { for byte in token_bytes.iter_mut() {
*byte = rng.gen(); *byte = rng.gen();
} }
base64::encode_config(token_bytes, base64::URL_SAFE) BASE64_URL_SAFE.encode(token_bytes)
} }
impl PublicKey { impl PublicKey {
@ -58,7 +59,7 @@ impl PublicKey {
EncryptionFormat::V1 => self.0.encrypt(&mut rng, oaep_sha256_padding(), bytes), EncryptionFormat::V1 => self.0.encrypt(&mut rng, oaep_sha256_padding(), bytes),
} }
.context("failed to encrypt string with public key")?; .context("failed to encrypt string with public key")?;
let encrypted_string = base64::encode_config(&encrypted_bytes, base64::URL_SAFE); let encrypted_string = BASE64_URL_SAFE.encode(&encrypted_bytes);
Ok(encrypted_string) Ok(encrypted_string)
} }
} }
@ -66,7 +67,8 @@ impl PublicKey {
impl PrivateKey { impl PrivateKey {
/// Decrypt a base64-encoded string that was encrypted by the corresponding public key. /// Decrypt a base64-encoded string that was encrypted by the corresponding public key.
pub fn decrypt_string(&self, encrypted_string: &str) -> Result<String> { pub fn decrypt_string(&self, encrypted_string: &str) -> Result<String> {
let encrypted_bytes = base64::decode_config(encrypted_string, base64::URL_SAFE) let encrypted_bytes = BASE64_URL_SAFE
.decode(encrypted_string)
.context("failed to base64-decode encrypted string")?; .context("failed to base64-decode encrypted string")?;
let bytes = self let bytes = self
.0 .0
@ -89,7 +91,7 @@ impl TryFrom<PublicKey> for String {
.0 .0
.to_pkcs1_der() .to_pkcs1_der()
.context("failed to serialize public key")?; .context("failed to serialize public key")?;
let string = base64::encode_config(&bytes, base64::URL_SAFE); let string = BASE64_URL_SAFE.encode(&bytes);
Ok(string) Ok(string)
} }
} }
@ -97,7 +99,8 @@ impl TryFrom<PublicKey> for String {
impl TryFrom<String> for PublicKey { impl TryFrom<String> for PublicKey {
type Error = anyhow::Error; type Error = anyhow::Error;
fn try_from(value: String) -> Result<Self> { fn try_from(value: String) -> Result<Self> {
let bytes = base64::decode_config(&value, base64::URL_SAFE) let bytes = BASE64_URL_SAFE
.decode(&value)
.context("failed to base64-decode public key string")?; .context("failed to base64-decode public key string")?;
let key = Self(RsaPublicKey::from_pkcs1_der(&bytes).context("failed to parse public key")?); let key = Self(RsaPublicKey::from_pkcs1_der(&bytes).context("failed to parse public key")?);
Ok(key) Ok(key)