feat: v0.1.0, encrypt works

This commit is contained in:
2023-09-30 19:43:29 +08:00
parent c317a80119
commit 712e50319a
11 changed files with 143 additions and 35 deletions

View File

@@ -12,6 +12,8 @@ pub const ENC_AES256_GCM_P256: &str = "aes256-gcm-p256";
pub const TINY_ENC_FILE_EXT: &str = ".tinyenc";
pub const TINY_ENC_CONFIG_FILE: &str = "~/.tinyencrypt/config-rs.json";
pub const TINY_ENC_MAGIC_TAG: u16 = 0x01;
pub fn require_tiny_enc_file_and_exists(path: impl AsRef<Path>) -> XResult<()> {
let path = path.as_ref();
let path_display = format!("{}", path.display());
@@ -22,6 +24,16 @@ pub fn require_tiny_enc_file_and_exists(path: impl AsRef<Path>) -> XResult<()> {
Ok(())
}
pub fn require_none_tiny_enc_file_and_exists(path: impl AsRef<Path>) -> XResult<()> {
let path = path.as_ref();
let path_display = format!("{}", path.display());
if path_display.ends_with(TINY_ENC_FILE_EXT) {
return simple_error!("File is already tiny encrypt file: {}", &path_display);
}
require_file_exists(path)?;
Ok(())
}
pub fn require_file_exists(path: impl AsRef<Path>) -> XResult<()> {
let path = path.as_ref();
match fs::metadata(path) {