mirror of
https://git.um-react.app/um/lib_um_crypto_rust.git
synced 2026-03-08 04:29:54 +00:00
refactor: move base64 to shared utils package
This commit is contained in:
7
um_crypto/utils/Cargo.toml
Normal file
7
um_crypto/utils/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "umc_utils"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
base64 = "0.22.1"
|
||||
22
um_crypto/utils/src/base64.rs
Normal file
22
um_crypto/utils/src/base64.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use base64::engine::{DecodePaddingMode, GeneralPurpose as Base64Engine, GeneralPurposeConfig};
|
||||
use base64::{alphabet, DecodeError, Engine};
|
||||
|
||||
/// Don't add padding when encoding, and require no padding when decoding.
|
||||
pub const ENGINE: Base64Engine = Base64Engine::new(
|
||||
&alphabet::STANDARD,
|
||||
GeneralPurposeConfig::new().with_decode_padding_mode(DecodePaddingMode::Indifferent),
|
||||
);
|
||||
|
||||
pub fn encode<T>(data: T) -> String
|
||||
where
|
||||
T: AsRef<[u8]>,
|
||||
{
|
||||
ENGINE.encode(data)
|
||||
}
|
||||
|
||||
pub fn decode<T>(data: T) -> Result<Vec<u8>, DecodeError>
|
||||
where
|
||||
T: AsRef<[u8]>,
|
||||
{
|
||||
ENGINE.decode(data)
|
||||
}
|
||||
1
um_crypto/utils/src/lib.rs
Normal file
1
um_crypto/utils/src/lib.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod base64;
|
||||
Reference in New Issue
Block a user