feat: v0.9.0, support secure editor
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1657,7 +1657,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tiny-encrypt"
|
||||
version = "0.8.2"
|
||||
version = "0.9.0"
|
||||
dependencies = [
|
||||
"aes-gcm-stream",
|
||||
"base64",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tiny-encrypt"
|
||||
version = "0.8.2"
|
||||
version = "0.9.0"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
description = "A simple and tiny file encrypt tool"
|
||||
|
||||
12
README.md
12
README.md
@@ -24,6 +24,18 @@ Compile only encrypt:
|
||||
cargo build --release --no-default-features
|
||||
```
|
||||
|
||||
Edit encrypted file:
|
||||
```shell
|
||||
tiny-encrypt decrypt --edit-file sample.txt.tinyenc
|
||||
```
|
||||
Read environment `EDITOR` or `SECURE_EDITOR` to edit file, `SECURE_EDITOR` write encrypted file to temp file.
|
||||
|
||||
Secure editor command format:
|
||||
```shell
|
||||
$SECURE_EDITOR <temp-file-name> "aes-256-gcm" <temp-key-hex> <temp-nonce-hex>
|
||||
```
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
Encrypt config `~/.tinyencrypt/config-rs.json`:
|
||||
|
||||
@@ -218,6 +218,10 @@ pub fn decrypt_single(config: &Option<TinyEncryptConfig>,
|
||||
let mut meta = meta;
|
||||
meta.file_length = temp_file_content.len() as u64;
|
||||
meta.file_last_modified = util_time::get_current_millis() as u64;
|
||||
match &mut meta.file_edit_count {
|
||||
None => { meta.file_edit_count = Some(1); }
|
||||
Some(file_edit_count) => { *file_edit_count += 1; }
|
||||
}
|
||||
let mut file_out = File::create(path)?;
|
||||
let _ = util_enc_file::write_tiny_encrypt_meta(&mut file_out, &meta, is_meta_compressed)?;
|
||||
let compress_level = iff!(meta.compress, Some(Compression::default().level()), None);
|
||||
|
||||
@@ -79,16 +79,22 @@ pub fn info_single(path: &PathBuf, cmd_info: &CmdInfo) -> XResult<()> {
|
||||
|
||||
let now_millis = util_time::get_current_millis() as u64;
|
||||
let fmt = simpledateformat::fmt(DATE_TIME_FORMAT).unwrap();
|
||||
infos.push(format!("{}: {}, {} ago",
|
||||
header("Last modified"),
|
||||
fmt.format_local(SystemTime::from_millis(meta.file_last_modified)),
|
||||
format_human2(Duration::from_millis(now_millis - meta.file_last_modified))
|
||||
));
|
||||
infos.push(format!("{}: {}, {} ago",
|
||||
header("Created"),
|
||||
fmt.format_local(SystemTime::from_millis(meta.created)),
|
||||
format_human2(Duration::from_millis(now_millis - meta.created))
|
||||
));
|
||||
infos.push(format!("{}: {}, {} ago",
|
||||
header("Last modified"),
|
||||
fmt.format_local(SystemTime::from_millis(meta.file_last_modified)),
|
||||
format_human2(Duration::from_millis(now_millis - meta.file_last_modified))
|
||||
));
|
||||
if let Some(file_edit_count) = meta.file_edit_count {
|
||||
infos.push(format!("{}: {} time(s)",
|
||||
header("Edit count"),
|
||||
file_edit_count
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(envelops) = meta.envelops.as_ref() {
|
||||
envelops.iter().enumerate().for_each(|(i, envelop)| {
|
||||
|
||||
@@ -48,6 +48,7 @@ pub struct TinyEncryptMeta {
|
||||
pub nonce: String,
|
||||
pub file_length: u64,
|
||||
pub file_last_modified: u64,
|
||||
pub file_edit_count: Option<u64>,
|
||||
pub compress: bool,
|
||||
}
|
||||
|
||||
@@ -161,6 +162,7 @@ impl TinyEncryptMeta {
|
||||
Ok(modified) => get_millis(&modified) as u64,
|
||||
Err(_) => 0,
|
||||
},
|
||||
file_edit_count: None,
|
||||
compress: enc_metadata.compress,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user