feat: PGP decrypt works
This commit is contained in:
30
src/util.rs
30
src/util.rs
@@ -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"),
|
||||
|
||||
Reference in New Issue
Block a user