feat: optimize
This commit is contained in:
@@ -138,10 +138,10 @@ pub fn decrypt_single(config: &Option<TinyEncryptConfig>,
|
|||||||
|
|
||||||
let key = SecVec(try_decrypt_key(config, selected_envelop, pin, slot)?);
|
let key = SecVec(try_decrypt_key(config, selected_envelop, pin, slot)?);
|
||||||
let nonce = SecVec(opt_result!(util::decode_base64(&meta.nonce), "Decode nonce failed: {}"));
|
let nonce = SecVec(opt_result!(util::decode_base64(&meta.nonce), "Decode nonce failed: {}"));
|
||||||
let key_nonce = KeyNonce { k: &key.0, n: &nonce.0 };
|
let key_nonce = KeyNonce { k: key.as_ref(), n: nonce.as_ref() };
|
||||||
|
|
||||||
// debugging!("Decrypt key: {}", hex::encode(&key.0));
|
// debugging!("Decrypt key: {}", hex::encode(&key.0));
|
||||||
util_msg::when_debug(|| debugging!("Decrypt nonce: {}", hex::encode(&nonce.0)));
|
util_msg::when_debug(|| debugging!("Decrypt nonce: {}", hex::encode(nonce.as_ref())));
|
||||||
|
|
||||||
let enc_meta = parse_encrypted_meta(&meta, cryptor, &key_nonce)?;
|
let enc_meta = parse_encrypted_meta(&meta, cryptor, &key_nonce)?;
|
||||||
parse_encrypted_comment(&meta, cryptor, &key_nonce)?;
|
parse_encrypted_comment(&meta, cryptor, &key_nonce)?;
|
||||||
|
|||||||
@@ -132,9 +132,9 @@ pub fn encrypt_single_file_out(path: &PathBuf, path_out: &str, envelops: &[&Tiny
|
|||||||
util::require_file_not_exists(path_out)?;
|
util::require_file_not_exists(path_out)?;
|
||||||
|
|
||||||
let (key, nonce) = util::make_key256_and_nonce();
|
let (key, nonce) = util::make_key256_and_nonce();
|
||||||
let key_nonce = KeyNonce { k: &key.0, n: &nonce.0 };
|
let key_nonce = KeyNonce { k: key.as_ref(), n: nonce.as_ref() };
|
||||||
// Encrypt session key to envelops
|
// Encrypt session key to envelops
|
||||||
let envelops = encrypt_envelops(cryptor, &key.0, envelops)?;
|
let envelops = encrypt_envelops(cryptor, key.as_ref(), envelops)?;
|
||||||
|
|
||||||
let encrypted_comment = match &cmd_encrypt.encrypted_comment {
|
let encrypted_comment = match &cmd_encrypt.encrypted_comment {
|
||||||
None => None,
|
None => None,
|
||||||
@@ -162,7 +162,7 @@ pub fn encrypt_single_file_out(path: &PathBuf, path_out: &str, envelops: &[&Tiny
|
|||||||
};
|
};
|
||||||
|
|
||||||
let encrypt_meta = TinyEncryptMeta::new(
|
let encrypt_meta = TinyEncryptMeta::new(
|
||||||
&file_metadata, &enc_metadata, cryptor, &nonce.0, envelops);
|
&file_metadata, &enc_metadata, cryptor, nonce.as_ref(), envelops);
|
||||||
debugging!("Encrypted meta: {:?}", encrypt_meta);
|
debugging!("Encrypted meta: {:?}", encrypt_meta);
|
||||||
|
|
||||||
let mut file_out = File::create(path_out)?;
|
let mut file_out = File::create(path_out)?;
|
||||||
@@ -305,7 +305,7 @@ fn encrypt_envelop_shared_secret(cryptor: Cryptor,
|
|||||||
envelop: &TinyEncryptConfigEnvelop) -> XResult<TinyEncryptEnvelop> {
|
envelop: &TinyEncryptConfigEnvelop) -> XResult<TinyEncryptEnvelop> {
|
||||||
let shared_key = util::simple_kdf(shared_secret);
|
let shared_key = util::simple_kdf(shared_secret);
|
||||||
let nonce = util::make_nonce();
|
let nonce = util::make_nonce();
|
||||||
let key_nonce = KeyNonce { k: &shared_key, n: &nonce.0 };
|
let key_nonce = KeyNonce { k: &shared_key, n: nonce.as_ref() };
|
||||||
|
|
||||||
let encrypted_key = crypto_simple::encrypt(
|
let encrypted_key = crypto_simple::encrypt(
|
||||||
cryptor, &key_nonce, key)?;
|
cryptor, &key_nonce, key)?;
|
||||||
|
|||||||
@@ -19,6 +19,12 @@ impl Drop for SecVec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AsRef<[u8]> for SecVec {
|
||||||
|
fn as_ref(&self) -> &[u8] {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn read_pin(pin: &Option<String>) -> String {
|
pub fn read_pin(pin: &Option<String>) -> String {
|
||||||
match pin {
|
match pin {
|
||||||
Some(pin) => pin.to_string(),
|
Some(pin) => pin.to_string(),
|
||||||
|
|||||||
Reference in New Issue
Block a user