feat: update version
This commit is contained in:
@@ -197,7 +197,7 @@ fn process_compatible_with_1_0(cmd_encrypt: &CmdEncrypt, mut encrypt_meta: TinyE
|
||||
Ok(encrypt_meta)
|
||||
}
|
||||
|
||||
fn encrypt_file(file_in: &mut File, file_len: u64, file_out: &mut File,
|
||||
fn encrypt_file(file_in: &mut File, file_len: u64, file_out: &mut impl Write,
|
||||
key: &[u8], nonce: &[u8], compress: bool, compress_level: &Option<u32>) -> XResult<u64> {
|
||||
let mut total_len = 0_u64;
|
||||
let mut write_len = 0_u64;
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
use clap::Args;
|
||||
use rust_util::XResult;
|
||||
use crate::util;
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
pub struct CmdVersion {}
|
||||
|
||||
pub fn version(_cmd_version: CmdVersion) -> XResult<()> {
|
||||
println!(
|
||||
"{} - v{}\n{}\n",
|
||||
env!("CARGO_PKG_NAME"),
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
env!("CARGO_PKG_DESCRIPTION")
|
||||
"User-Agent: {}\n{}",
|
||||
util::get_user_agent(),
|
||||
env!("CARGO_PKG_DESCRIPTION"),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
75
src/util.rs
75
src/util.rs
@@ -133,31 +133,62 @@ pub fn read_number(hint: &str, from: usize, to: usize) -> usize {
|
||||
}
|
||||
|
||||
pub fn get_user_agent() -> String {
|
||||
format!("TinyEncrypt-rs v{}@{}", env!("CARGO_PKG_VERSION"),
|
||||
if cfg!(target_os = "macos") {
|
||||
"MacOS"
|
||||
} else if cfg!(target_os = "ios") {
|
||||
"iOS"
|
||||
} else if cfg!(target_os = "android") {
|
||||
"Android"
|
||||
} else if cfg!(target_os = "windows") {
|
||||
"Windows"
|
||||
} else if cfg!(target_os = "linux") {
|
||||
"Linux"
|
||||
} else if cfg!(target_os = "freebsd") {
|
||||
"FreeBSD"
|
||||
} else if cfg!(target_os = "dragonfly") {
|
||||
"Dragonfly"
|
||||
} else if cfg!(target_os = "openbsd") {
|
||||
"OpenBSD"
|
||||
} else if cfg!(target_os = "netbsd") {
|
||||
"NetBSD"
|
||||
} else {
|
||||
panic!("Unsupported OS!");
|
||||
}
|
||||
format!("TinyEncrypt-rs v{}@{}-{}",
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
get_os(), get_arch(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_os() -> String {
|
||||
if cfg!(target_os = "macos") {
|
||||
"MacOS"
|
||||
} else if cfg!(target_os = "ios") {
|
||||
"iOS"
|
||||
} else if cfg!(target_os = "android") {
|
||||
"Android"
|
||||
} else if cfg!(target_os = "windows") {
|
||||
"Windows"
|
||||
} else if cfg!(target_os = "linux") {
|
||||
"Linux"
|
||||
} else if cfg!(target_os = "freebsd") {
|
||||
"FreeBSD"
|
||||
} else if cfg!(target_os = "dragonfly") {
|
||||
"Dragonfly"
|
||||
} else if cfg!(target_os = "openbsd") {
|
||||
"OpenBSD"
|
||||
} else if cfg!(target_os = "netbsd") {
|
||||
"NetBSD"
|
||||
} else {
|
||||
"UnknownOS"
|
||||
}.to_string()
|
||||
}
|
||||
|
||||
pub fn get_arch() -> String {
|
||||
if cfg!(target_arch = "x86_64") {
|
||||
"x86-64"
|
||||
} else if cfg!(target_arch = "x86") {
|
||||
"x86"
|
||||
} else if cfg!(target_arch = "aarch64") {
|
||||
"aarch64"
|
||||
} else if cfg!(target_arch = "arm") {
|
||||
"arm"
|
||||
} else if cfg!(target_arch = "riscv64") {
|
||||
"riscv64"
|
||||
} else if cfg!(target_arch = "riscv32") {
|
||||
"riscv32"
|
||||
} else if cfg!(target_arch = "mips64") {
|
||||
"mips64"
|
||||
} else if cfg!(target_arch = "mips") {
|
||||
"mips"
|
||||
} else if cfg!(target_arch = "powerpc64") {
|
||||
"powerpc64"
|
||||
} else if cfg!(target_arch = "powerpc") {
|
||||
"powerpc"
|
||||
} else {
|
||||
"unknown"
|
||||
}.to_string()
|
||||
}
|
||||
|
||||
pub fn zeroize(object: impl Zeroize) {
|
||||
let mut object = object;
|
||||
object.zeroize();
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::compress;
|
||||
use crate::consts::{TINY_ENC_COMPRESSED_MAGIC_TAG, TINY_ENC_MAGIC_TAG};
|
||||
use crate::spec::TinyEncryptMeta;
|
||||
|
||||
pub fn write_tiny_encrypt_meta<W: Write>(w: &mut W, meta: &TinyEncryptMeta, compress_meta: bool) -> XResult<usize> {
|
||||
pub fn write_tiny_encrypt_meta(w: &mut impl Write, meta: &TinyEncryptMeta, compress_meta: bool) -> XResult<usize> {
|
||||
let tag = iff!(compress_meta, TINY_ENC_COMPRESSED_MAGIC_TAG, TINY_ENC_MAGIC_TAG);
|
||||
opt_result!(w.write_all(&tag.to_be_bytes()), "Write tag failed: {}");
|
||||
let mut encrypted_meta_bytes = opt_result!(serde_json::to_vec(&meta), "Generate meta json bytes failed: {}");
|
||||
@@ -23,13 +23,13 @@ pub fn write_tiny_encrypt_meta<W: Write>(w: &mut W, meta: &TinyEncryptMeta, comp
|
||||
Ok(encrypted_meta_bytes.len() + 2 + 4)
|
||||
}
|
||||
|
||||
pub fn read_tiny_encrypt_meta_and_normalize<R: Read>(r: &mut R) -> XResult<TinyEncryptMeta> {
|
||||
pub fn read_tiny_encrypt_meta_and_normalize(r: &mut impl Read) -> XResult<TinyEncryptMeta> {
|
||||
let mut meta = read_tiny_encrypt_meta(r);
|
||||
let _ = meta.as_mut().map(|meta| meta.normalize());
|
||||
meta
|
||||
}
|
||||
|
||||
pub fn read_tiny_encrypt_meta<R: Read>(r: &mut R) -> XResult<TinyEncryptMeta> {
|
||||
pub fn read_tiny_encrypt_meta(r: &mut impl Read) -> XResult<TinyEncryptMeta> {
|
||||
let mut tag_buff = [0_u8; 2];
|
||||
opt_result!(r.read_exact(&mut tag_buff), "Read tag failed: {}");
|
||||
let tag = u16::from_be_bytes(tag_buff);
|
||||
@@ -42,7 +42,7 @@ pub fn read_tiny_encrypt_meta<R: Read>(r: &mut R) -> XResult<TinyEncryptMeta> {
|
||||
let mut length_buff = [0_u8; 4];
|
||||
opt_result!(r.read_exact(&mut length_buff), "Read length failed: {}");
|
||||
let length = u32::from_be_bytes(length_buff);
|
||||
if length > 1024 * 1024 {
|
||||
if length > 100 * 1024 * 1024 {
|
||||
return simple_error!("Meta too large: {}", length);
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ pub fn read_tiny_encrypt_meta<R: Read>(r: &mut R) -> XResult<TinyEncryptMeta> {
|
||||
debugging!("Tiny enc meta compressed: {}", is_compressed_tiny_enc);
|
||||
if is_compressed_tiny_enc {
|
||||
meta_buff = opt_result!(compress::decompress(&meta_buff), "Decompress meta failed: {}");
|
||||
debugging!("Encrypted meta decompressed: {} byte(s) -> {} byte(s)", length, meta_buff.len());
|
||||
}
|
||||
debugging!("Encrypted meta: {}", String::from_utf8_lossy(&meta_buff));
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ pub fn read_and_verify_openpgp_pin(trans: &mut OpenPgpTransaction, pin: &Option<
|
||||
pub fn get_openpgp() -> XResult<OpenPgp> {
|
||||
let card = match get_card() {
|
||||
Err(e) => {
|
||||
failure!("Get PGP card failed: {}", e);
|
||||
return simple_error!("Get card failed: {}", e);
|
||||
}
|
||||
Ok(card) => card
|
||||
|
||||
Reference in New Issue
Block a user