Upgrade base64

This commit is contained in:
Zhaofeng Li 2023-03-05 11:05:11 -07:00
parent 7f62e92d71
commit 97285de54f
9 changed files with 22 additions and 22 deletions

12
Cargo.lock generated
View file

@ -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"

View file

@ -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"

View file

@ -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 {

View file

@ -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"] }

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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<HS256Key> {
let secret = base64::decode(s).map_err(Error::Base64Error)?;
let secret = BASE64_STANDARD.decode(s).map_err(Error::Base64Error)?;
Ok(HS256Key::from_bytes(&secret))
}

View file

@ -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<String> {
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(':')?;