feat: update version

This commit is contained in:
2023-10-19 23:24:03 +08:00
parent 94a6cf18b3
commit a66babb828
5 changed files with 63 additions and 32 deletions

View File

@@ -197,7 +197,7 @@ fn process_compatible_with_1_0(cmd_encrypt: &CmdEncrypt, mut encrypt_meta: TinyE
Ok(encrypt_meta) 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> { key: &[u8], nonce: &[u8], compress: bool, compress_level: &Option<u32>) -> XResult<u64> {
let mut total_len = 0_u64; let mut total_len = 0_u64;
let mut write_len = 0_u64; let mut write_len = 0_u64;

View File

@@ -1,15 +1,15 @@
use clap::Args; use clap::Args;
use rust_util::XResult; use rust_util::XResult;
use crate::util;
#[derive(Debug, Args)] #[derive(Debug, Args)]
pub struct CmdVersion {} pub struct CmdVersion {}
pub fn version(_cmd_version: CmdVersion) -> XResult<()> { pub fn version(_cmd_version: CmdVersion) -> XResult<()> {
println!( println!(
"{} - v{}\n{}\n", "User-Agent: {}\n{}",
env!("CARGO_PKG_NAME"), util::get_user_agent(),
env!("CARGO_PKG_VERSION"), env!("CARGO_PKG_DESCRIPTION"),
env!("CARGO_PKG_DESCRIPTION")
); );
Ok(()) Ok(())
} }

View File

@@ -133,7 +133,13 @@ pub fn read_number(hint: &str, from: usize, to: usize) -> usize {
} }
pub fn get_user_agent() -> String { pub fn get_user_agent() -> String {
format!("TinyEncrypt-rs v{}@{}", env!("CARGO_PKG_VERSION"), format!("TinyEncrypt-rs v{}@{}-{}",
env!("CARGO_PKG_VERSION"),
get_os(), get_arch(),
)
}
pub fn get_os() -> String {
if cfg!(target_os = "macos") { if cfg!(target_os = "macos") {
"MacOS" "MacOS"
} else if cfg!(target_os = "ios") { } else if cfg!(target_os = "ios") {
@@ -153,9 +159,34 @@ pub fn get_user_agent() -> String {
} else if cfg!(target_os = "netbsd") { } else if cfg!(target_os = "netbsd") {
"NetBSD" "NetBSD"
} else { } else {
panic!("Unsupported OS!"); "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) { pub fn zeroize(object: impl Zeroize) {

View File

@@ -7,7 +7,7 @@ use crate::compress;
use crate::consts::{TINY_ENC_COMPRESSED_MAGIC_TAG, TINY_ENC_MAGIC_TAG}; use crate::consts::{TINY_ENC_COMPRESSED_MAGIC_TAG, TINY_ENC_MAGIC_TAG};
use crate::spec::TinyEncryptMeta; 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); 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: {}"); 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: {}"); 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) 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 mut meta = read_tiny_encrypt_meta(r);
let _ = meta.as_mut().map(|meta| meta.normalize()); let _ = meta.as_mut().map(|meta| meta.normalize());
meta 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]; let mut tag_buff = [0_u8; 2];
opt_result!(r.read_exact(&mut tag_buff), "Read tag failed: {}"); opt_result!(r.read_exact(&mut tag_buff), "Read tag failed: {}");
let tag = u16::from_be_bytes(tag_buff); 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]; let mut length_buff = [0_u8; 4];
opt_result!(r.read_exact(&mut length_buff), "Read length failed: {}"); opt_result!(r.read_exact(&mut length_buff), "Read length failed: {}");
let length = u32::from_be_bytes(length_buff); let length = u32::from_be_bytes(length_buff);
if length > 1024 * 1024 { if length > 100 * 1024 * 1024 {
return simple_error!("Meta too large: {}", length); 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); debugging!("Tiny enc meta compressed: {}", is_compressed_tiny_enc);
if is_compressed_tiny_enc { if is_compressed_tiny_enc {
meta_buff = opt_result!(compress::decompress(&meta_buff), "Decompress meta failed: {}"); 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)); debugging!("Encrypted meta: {}", String::from_utf8_lossy(&meta_buff));

View File

@@ -17,7 +17,6 @@ pub fn read_and_verify_openpgp_pin(trans: &mut OpenPgpTransaction, pin: &Option<
pub fn get_openpgp() -> XResult<OpenPgp> { pub fn get_openpgp() -> XResult<OpenPgp> {
let card = match get_card() { let card = match get_card() {
Err(e) => { Err(e) => {
failure!("Get PGP card failed: {}", e);
return simple_error!("Get card failed: {}", e); return simple_error!("Get card failed: {}", e);
} }
Ok(card) => card Ok(card) => card