forked from nrabulinski/attic
Upgrade base64
This commit is contained in:
parent
7f62e92d71
commit
97285de54f
9 changed files with 22 additions and 22 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -172,7 +172,7 @@ name = "attic"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-stream",
|
"async-stream",
|
||||||
"base64 0.20.0",
|
"base64 0.21.0",
|
||||||
"bindgen",
|
"bindgen",
|
||||||
"bytes",
|
"bytes",
|
||||||
"cxx",
|
"cxx",
|
||||||
|
@ -243,7 +243,7 @@ dependencies = [
|
||||||
"aws-sdk-s3",
|
"aws-sdk-s3",
|
||||||
"axum",
|
"axum",
|
||||||
"axum-macros",
|
"axum-macros",
|
||||||
"base64 0.20.0",
|
"base64 0.21.0",
|
||||||
"bytes",
|
"bytes",
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap 4.1.8",
|
"clap 4.1.8",
|
||||||
|
@ -285,7 +285,7 @@ name = "attic-token"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"attic",
|
"attic",
|
||||||
"base64 0.20.0",
|
"base64 0.21.0",
|
||||||
"chrono",
|
"chrono",
|
||||||
"displaydoc",
|
"displaydoc",
|
||||||
"jwt-simple",
|
"jwt-simple",
|
||||||
|
@ -776,12 +776,6 @@ version = "0.13.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "base64"
|
|
||||||
version = "0.20.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base64"
|
name = "base64"
|
||||||
version = "0.21.0"
|
version = "0.21.0"
|
||||||
|
|
|
@ -6,7 +6,7 @@ publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-stream = { version = "0.3.4", optional = true }
|
async-stream = { version = "0.3.4", optional = true }
|
||||||
base64 = "0.20.0"
|
base64 = "0.21.0"
|
||||||
bytes = "1.4.0"
|
bytes = "1.4.0"
|
||||||
displaydoc = "0.2.3"
|
displaydoc = "0.2.3"
|
||||||
digest = "0.10.6"
|
digest = "0.10.6"
|
||||||
|
|
|
@ -25,7 +25,7 @@ use std::convert::TryInto;
|
||||||
|
|
||||||
use serde::{de, ser, Deserialize, Serialize};
|
use serde::{de, ser, Deserialize, Serialize};
|
||||||
|
|
||||||
use base64::DecodeError;
|
use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, DecodeError, Engine};
|
||||||
use displaydoc::Display;
|
use displaydoc::Display;
|
||||||
use ed25519_compact::{Error as SignatureError, KeyPair, PublicKey, Signature};
|
use ed25519_compact::{Error as SignatureError, KeyPair, PublicKey, Signature};
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ impl NixKeypair {
|
||||||
/// For example, it can look like:
|
/// For example, it can look like:
|
||||||
/// attic-test:msdoldbtlongtt0/xkzmcbqihd7yvy8iomajqhnkutsl3b1pyyyc0mgg2rs0ttzzuyuk9rb2zphvtpes71mlha==
|
/// attic-test:msdoldbtlongtt0/xkzmcbqihd7yvy8iomajqhnkutsl3b1pyyyc0mgg2rs0ttzzuyuk9rb2zphvtpes71mlha==
|
||||||
pub fn export_keypair(&self) -> String {
|
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.
|
/// Returns the canonical representation of the public key.
|
||||||
|
@ -134,7 +134,7 @@ impl NixKeypair {
|
||||||
/// For example, it can look like:
|
/// For example, it can look like:
|
||||||
/// attic-test:C929acssgtJoINkUtLbc81GFJPUW9maR77TxEu9ZpRw=
|
/// attic-test:C929acssgtJoINkUtLbc81GFJPUW9maR77TxEu9ZpRw=
|
||||||
pub fn export_public_key(&self) -> String {
|
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.
|
/// Returns the public key portion of the keypair.
|
||||||
|
@ -148,7 +148,7 @@ impl NixKeypair {
|
||||||
/// Signs a message, returning its canonical representation.
|
/// Signs a message, returning its canonical representation.
|
||||||
pub fn sign(&self, message: &[u8]) -> String {
|
pub fn sign(&self, message: &[u8]) -> String {
|
||||||
let bytes = self.keypair.sk.sign(message, None);
|
let bytes = self.keypair.sk.sign(message, None);
|
||||||
format!("{}:{}", self.name, base64::encode(bytes))
|
format!("{}:{}", self.name, BASE64_STANDARD.encode(bytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verifies a message.
|
/// Verifies a message.
|
||||||
|
@ -205,7 +205,7 @@ impl NixPublicKey {
|
||||||
/// For example, it can look like:
|
/// For example, it can look like:
|
||||||
/// attic-test:C929acssgtJoINkUtLbc81GFJPUW9maR77TxEu9ZpRw=
|
/// attic-test:C929acssgtJoINkUtLbc81GFJPUW9maR77TxEu9ZpRw=
|
||||||
pub fn export(&self) -> String {
|
pub fn export(&self) -> String {
|
||||||
format!("{}:{}", self.name, base64::encode(*self.public))
|
format!("{}:{}", self.name, BASE64_STANDARD.encode(*self.public))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verifies a message.
|
/// 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 {
|
if bytes.len() != expected_payload_length {
|
||||||
return Err(Error::InvalidPayloadLength {
|
return Err(Error::InvalidPayloadLength {
|
||||||
|
|
|
@ -29,7 +29,7 @@ aws-config = "0.54.1"
|
||||||
aws-sdk-s3 = "0.24.0"
|
aws-sdk-s3 = "0.24.0"
|
||||||
axum = "0.6.10"
|
axum = "0.6.10"
|
||||||
axum-macros = "0.3.5"
|
axum-macros = "0.3.5"
|
||||||
base64 = "0.20.0"
|
base64 = "0.21.0"
|
||||||
bytes = "1.4.0"
|
bytes = "1.4.0"
|
||||||
chrono = "0.4.23"
|
chrono = "0.4.23"
|
||||||
clap = { version = "4.1", features = ["derive"] }
|
clap = { version = "4.1", features = ["derive"] }
|
||||||
|
|
|
@ -7,6 +7,7 @@ use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use async_compression::Level as CompressionLevel;
|
use async_compression::Level as CompressionLevel;
|
||||||
|
use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, Engine};
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
use serde::{de, Deserialize};
|
use serde::{de, Deserialize};
|
||||||
use xdg::BaseDirectories;
|
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 {
|
if let Some(config_path) = config_path {
|
||||||
load_config_from_path(config_path)
|
load_config_from_path(config_path)
|
||||||
} else if let Ok(config_env) = env::var(ENV_CONFIG_BASE64) {
|
} 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)
|
load_config_from_str(&decoded)
|
||||||
} else {
|
} else {
|
||||||
// Config from XDG
|
// Config from XDG
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
//! - NARs: `~/.local/share/attic/storage`
|
//! - NARs: `~/.local/share/attic/storage`
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, Engine};
|
||||||
use chrono::{Months, Utc};
|
use chrono::{Months, Utc};
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
@ -51,7 +52,7 @@ pub async fn run_oobe() -> Result<()> {
|
||||||
.map(char::from)
|
.map(char::from)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
base64::encode(random)
|
BASE64_STANDARD.encode(random)
|
||||||
};
|
};
|
||||||
|
|
||||||
let config_content = CONFIG_TEMPLATE
|
let config_content = CONFIG_TEMPLATE
|
||||||
|
|
|
@ -8,7 +8,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
attic = { path = "../attic", default-features = false }
|
attic = { path = "../attic", default-features = false }
|
||||||
|
|
||||||
base64 = "0.20.0"
|
base64 = "0.21.0"
|
||||||
chrono = "0.4.23"
|
chrono = "0.4.23"
|
||||||
displaydoc = "0.2.3"
|
displaydoc = "0.2.3"
|
||||||
jwt-simple = "0.11.4"
|
jwt-simple = "0.11.4"
|
||||||
|
|
|
@ -71,6 +71,7 @@ mod tests;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::error::Error as StdError;
|
use std::error::Error as StdError;
|
||||||
|
|
||||||
|
use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, Engine};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use displaydoc::Display;
|
use displaydoc::Display;
|
||||||
pub use jwt_simple::{
|
pub use jwt_simple::{
|
||||||
|
@ -361,7 +362,7 @@ impl Default for CachePermission {
|
||||||
impl StdError for Error {}
|
impl StdError for Error {}
|
||||||
|
|
||||||
pub fn decode_token_hs256_secret_base64(s: &str) -> Result<HS256Key> {
|
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))
|
Ok(HS256Key::from_bytes(&secret))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
|
use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, Engine};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ pub fn parse_authorization_header(authorization: &str) -> Option<String> {
|
||||||
Some(rest.to_string())
|
Some(rest.to_string())
|
||||||
} else {
|
} else {
|
||||||
// Basic auth
|
// Basic auth
|
||||||
let bytes = base64::decode(rest).ok()?;
|
let bytes = BASE64_STANDARD.decode(rest).ok()?;
|
||||||
|
|
||||||
let user_pass = str::from_utf8(&bytes).ok()?;
|
let user_pass = str::from_utf8(&bytes).ok()?;
|
||||||
let colon = user_pass.find(':')?;
|
let colon = user_pass.find(':')?;
|
||||||
|
|
Loading…
Reference in a new issue