feat: PGP decrypt works

This commit is contained in:
2023-09-07 01:08:12 +08:00
parent 34fd7d0e47
commit 8939237d99
5 changed files with 176 additions and 17 deletions

View File

@@ -1,3 +1,33 @@
use std::io;
use std::io::Write;
use base64::Engine;
use base64::engine::general_purpose;
use rust_util::{warning, XResult};
pub const TINY_ENC_FILE_EXT: &str = ".tinyenc";
pub fn decode_base64(input: &str) -> XResult<Vec<u8>> {
Ok(general_purpose::STANDARD.decode(input)?)
}
pub fn read_number(hint: &str, from: usize, to: usize) -> usize {
loop {
print!("{} ({}-{}): ", hint, from, to);
io::stdout().flush().ok();
let mut buff = String::new();
let _ = io::stdin().read_line(&mut buff).expect("Read line from stdin");
let buff = buff.trim();
match buff.parse() {
Err(_) => warning!("Input number error!"),
Ok(number) => if number < from || number > to {
warning!("Input number is not in range.");
} else {
return number;
},
}
}
}
pub fn get_user_agent() -> String {
format!("TinyEncrypt-rs v{}@{}", env!("CARGO_PKG_VERSION"),