From 97285de54ff8f236dc8ef4f957363e8a4bb51af2 Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Sun, 5 Mar 2023 11:05:11 -0700 Subject: [PATCH] Upgrade base64 --- Cargo.lock | 12 +++--------- attic/Cargo.toml | 2 +- attic/src/signing/mod.rs | 14 ++++++++------ server/Cargo.toml | 2 +- server/src/config.rs | 3 ++- server/src/oobe.rs | 3 ++- token/Cargo.toml | 2 +- token/src/lib.rs | 3 ++- token/src/util.rs | 3 ++- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fa3ea13..fb8d8db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -172,7 +172,7 @@ name = "attic" version = "0.1.0" dependencies = [ "async-stream", - "base64 0.20.0", + "base64 0.21.0", "bindgen", "bytes", "cxx", @@ -243,7 +243,7 @@ dependencies = [ "aws-sdk-s3", "axum", "axum-macros", - "base64 0.20.0", + "base64 0.21.0", "bytes", "chrono", "clap 4.1.8", @@ -285,7 +285,7 @@ name = "attic-token" version = "0.1.0" dependencies = [ "attic", - "base64 0.20.0", + "base64 0.21.0", "chrono", "displaydoc", "jwt-simple", @@ -776,12 +776,6 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" -[[package]] -name = "base64" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5" - [[package]] name = "base64" version = "0.21.0" diff --git a/attic/Cargo.toml b/attic/Cargo.toml index 63fe3f1..d1e38d3 100644 --- a/attic/Cargo.toml +++ b/attic/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] async-stream = { version = "0.3.4", optional = true } -base64 = "0.20.0" +base64 = "0.21.0" bytes = "1.4.0" displaydoc = "0.2.3" digest = "0.10.6" diff --git a/attic/src/signing/mod.rs b/attic/src/signing/mod.rs index 21aa38d..9565b45 100644 --- a/attic/src/signing/mod.rs +++ b/attic/src/signing/mod.rs @@ -25,7 +25,7 @@ use std::convert::TryInto; use serde::{de, ser, Deserialize, Serialize}; -use base64::DecodeError; +use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, DecodeError, Engine}; use displaydoc::Display; use ed25519_compact::{Error as SignatureError, KeyPair, PublicKey, Signature}; @@ -126,7 +126,7 @@ impl NixKeypair { /// For example, it can look like: /// attic-test:msdoldbtlongtt0/xkzmcbqihd7yvy8iomajqhnkutsl3b1pyyyc0mgg2rs0ttzzuyuk9rb2zphvtpes71mlha== pub fn export_keypair(&self) -> String { - format!("{}:{}", self.name, base64::encode(*self.keypair)) + format!("{}:{}", self.name, BASE64_STANDARD.encode(*self.keypair)) } /// Returns the canonical representation of the public key. @@ -134,7 +134,7 @@ impl NixKeypair { /// For example, it can look like: /// attic-test:C929acssgtJoINkUtLbc81GFJPUW9maR77TxEu9ZpRw= pub fn export_public_key(&self) -> String { - format!("{}:{}", self.name, base64::encode(*self.keypair.pk)) + format!("{}:{}", self.name, BASE64_STANDARD.encode(*self.keypair.pk)) } /// Returns the public key portion of the keypair. @@ -148,7 +148,7 @@ impl NixKeypair { /// Signs a message, returning its canonical representation. pub fn sign(&self, message: &[u8]) -> String { let bytes = self.keypair.sk.sign(message, None); - format!("{}:{}", self.name, base64::encode(bytes)) + format!("{}:{}", self.name, BASE64_STANDARD.encode(bytes)) } /// Verifies a message. @@ -205,7 +205,7 @@ impl NixPublicKey { /// For example, it can look like: /// attic-test:C929acssgtJoINkUtLbc81GFJPUW9maR77TxEu9ZpRw= pub fn export(&self) -> String { - format!("{}:{}", self.name, base64::encode(*self.public)) + format!("{}:{}", self.name, BASE64_STANDARD.encode(*self.public)) } /// Verifies a message. @@ -256,7 +256,9 @@ fn decode_string<'s>( } } - let bytes = base64::decode(&colon_and_payload[1..]).map_err(Error::Base64DecodeError)?; + let bytes = BASE64_STANDARD + .decode(&colon_and_payload[1..]) + .map_err(Error::Base64DecodeError)?; if bytes.len() != expected_payload_length { return Err(Error::InvalidPayloadLength { diff --git a/server/Cargo.toml b/server/Cargo.toml index fa89816..d9333ea 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -29,7 +29,7 @@ aws-config = "0.54.1" aws-sdk-s3 = "0.24.0" axum = "0.6.10" axum-macros = "0.3.5" -base64 = "0.20.0" +base64 = "0.21.0" bytes = "1.4.0" chrono = "0.4.23" clap = { version = "4.1", features = ["derive"] } diff --git a/server/src/config.rs b/server/src/config.rs index 5ee6f51..da7999f 100644 --- a/server/src/config.rs +++ b/server/src/config.rs @@ -7,6 +7,7 @@ use std::time::Duration; use anyhow::Result; use async_compression::Level as CompressionLevel; +use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, Engine}; use derivative::Derivative; use serde::{de, Deserialize}; use xdg::BaseDirectories; @@ -348,7 +349,7 @@ pub async fn load_config(config_path: Option<&Path>, allow_oobe: bool) -> Result if let Some(config_path) = config_path { load_config_from_path(config_path) } else if let Ok(config_env) = env::var(ENV_CONFIG_BASE64) { - let decoded = String::from_utf8(base64::decode(config_env.as_bytes())?)?; + let decoded = String::from_utf8(BASE64_STANDARD.decode(config_env.as_bytes())?)?; load_config_from_str(&decoded) } else { // Config from XDG diff --git a/server/src/oobe.rs b/server/src/oobe.rs index e606d1e..c26fff2 100644 --- a/server/src/oobe.rs +++ b/server/src/oobe.rs @@ -12,6 +12,7 @@ //! - NARs: `~/.local/share/attic/storage` use anyhow::Result; +use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, Engine}; use chrono::{Months, Utc}; use rand::distributions::Alphanumeric; use rand::Rng; @@ -51,7 +52,7 @@ pub async fn run_oobe() -> Result<()> { .map(char::from) .collect(); - base64::encode(random) + BASE64_STANDARD.encode(random) }; let config_content = CONFIG_TEMPLATE diff --git a/token/Cargo.toml b/token/Cargo.toml index bed6fc6..52c40e5 100644 --- a/token/Cargo.toml +++ b/token/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] attic = { path = "../attic", default-features = false } -base64 = "0.20.0" +base64 = "0.21.0" chrono = "0.4.23" displaydoc = "0.2.3" jwt-simple = "0.11.4" diff --git a/token/src/lib.rs b/token/src/lib.rs index f25c784..ebfadc4 100644 --- a/token/src/lib.rs +++ b/token/src/lib.rs @@ -71,6 +71,7 @@ mod tests; use std::collections::HashMap; use std::error::Error as StdError; +use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, Engine}; use chrono::{DateTime, Utc}; use displaydoc::Display; pub use jwt_simple::{ @@ -361,7 +362,7 @@ impl Default for CachePermission { impl StdError for Error {} pub fn decode_token_hs256_secret_base64(s: &str) -> Result { - let secret = base64::decode(s).map_err(Error::Base64Error)?; + let secret = BASE64_STANDARD.decode(s).map_err(Error::Base64Error)?; Ok(HS256Key::from_bytes(&secret)) } diff --git a/token/src/util.rs b/token/src/util.rs index c933347..3d93d25 100644 --- a/token/src/util.rs +++ b/token/src/util.rs @@ -1,5 +1,6 @@ use std::str; +use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, Engine}; use lazy_static::lazy_static; use regex::Regex; @@ -18,7 +19,7 @@ pub fn parse_authorization_header(authorization: &str) -> Option { Some(rest.to_string()) } else { // Basic auth - let bytes = base64::decode(rest).ok()?; + let bytes = BASE64_STANDARD.decode(rest).ok()?; let user_pass = str::from_utf8(&bytes).ok()?; let colon = user_pass.find(':')?;