feat: v1.9.4
This commit is contained in:
11
src/util.rs
11
src/util.rs
@@ -1,5 +1,6 @@
|
||||
use base64::{DecodeError, Engine};
|
||||
use base64::engine::general_purpose::{STANDARD, URL_SAFE_NO_PAD};
|
||||
use rust_util::XResult;
|
||||
|
||||
pub fn base64_encode<T: AsRef<[u8]>>(input: T) -> String {
|
||||
STANDARD.encode(input)
|
||||
@@ -12,3 +13,13 @@ pub fn base64_encode_url_safe_no_pad<T: AsRef<[u8]>>(input: T) -> String {
|
||||
pub fn base64_decode<T: AsRef<[u8]>>(input: T) -> Result<Vec<u8>, DecodeError> {
|
||||
STANDARD.decode(input)
|
||||
}
|
||||
|
||||
pub fn try_decode(input: &str) -> XResult<Vec<u8>> {
|
||||
return match hex::decode(input) {
|
||||
Ok(v) => Ok(v),
|
||||
Err(_) => match base64_decode(input) {
|
||||
Ok(v) => Ok(v),
|
||||
Err(e) => simple_error!("decode hex or base64 error: {}", e),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user