util: add base64 transcoding wrappers

anna 1 year ago
parent f54a172e07
commit f13c3a3dbe
Signed by: fef
GPG Key ID: EC22E476DC2D3D84

17
Cargo.lock generated

@ -30,7 +30,7 @@ dependencies = [
"actix-service",
"actix-utils",
"ahash 0.7.6",
"base64",
"base64 0.13.1",
"bitflags",
"brotli",
"bytes",
@ -297,6 +297,12 @@ version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]]
name = "base64"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
[[package]]
name = "base64ct"
version = "1.5.3"
@ -1286,7 +1292,7 @@ version = "8.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09f4f04699947111ec1733e71778d763555737579e44b85844cae8e1940a1828"
dependencies = [
"base64",
"base64 0.13.1",
"ring",
"serde",
"serde_json",
@ -1614,6 +1620,7 @@ dependencies = [
"actix-web",
"argon2",
"async-trait",
"base64 0.21.0",
"bytes",
"chrono",
"dotenvy",
@ -1991,7 +1998,7 @@ version = "0.11.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c"
dependencies = [
"base64",
"base64 0.13.1",
"bytes",
"encoding_rs",
"futures-core",
@ -2086,7 +2093,7 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55"
dependencies = [
"base64",
"base64 0.13.1",
]
[[package]]
@ -2340,7 +2347,7 @@ checksum = "dcbc16ddba161afc99e14d1713a453747a2b07fc097d2009f4c300ec99286105"
dependencies = [
"ahash 0.7.6",
"atoi",
"base64",
"base64 0.13.1",
"bitflags",
"byteorder",
"bytes",

@ -8,6 +8,7 @@ actix-rt = "2.7"
actix-web = "4"
argon2 = "0.4"
async-trait = "0.1.59"
base64 = "0.21"
bytes = "1.3"
chrono = { version = "0.4", features = [ "alloc", "clock", "serde" ] }
dotenvy = "0.15.6"

@ -3,4 +3,5 @@ pub mod crypto;
pub mod http;
pub mod password;
pub mod token;
pub mod transcode;
pub mod validate;

@ -0,0 +1,20 @@
use base64::{
alphabet,
engine::{GeneralPurpose, GeneralPurposeConfig},
Engine,
};
use bytes::Bytes;
use crate::core::*;
static ENGINE: GeneralPurpose =
GeneralPurpose::new(&alphabet::STANDARD, GeneralPurposeConfig::new());
pub fn base64_decode(s: &str) -> Result<Bytes> {
let bytes = ENGINE.decode(s).map_err(|_| Error::Base64)?;
Ok(Bytes::from(bytes))
}
pub fn base64_encode(b: &[u8]) -> String {
ENGINE.encode(b)
}
Loading…
Cancel
Save