feat: v1.9.6

This commit is contained in:
2024-06-16 10:20:23 +08:00
parent d4b9b852c1
commit 7d5af78078
6 changed files with 36 additions and 13 deletions

View File

@@ -1,3 +1,5 @@
use std::io::Read;
use base64::{DecodeError, Engine};
use base64::engine::general_purpose::{STANDARD, URL_SAFE_NO_PAD};
use rust_util::XResult;
@@ -15,11 +17,18 @@ pub fn base64_decode<T: AsRef<[u8]>>(input: T) -> Result<Vec<u8>, DecodeError> {
}
pub fn try_decode(input: &str) -> XResult<Vec<u8>> {
return match hex::decode(input) {
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),
}
};
}
}
pub fn read_stdin() -> XResult<Vec<u8>> {
let mut buffer = vec![];
let mut stdin = std::io::stdin();
opt_result!(stdin.read_to_end(&mut buffer), "Read stdin failed: {}");
Ok(buffer)
}