feat: resorder envelops

This commit is contained in:
2023-10-01 12:15:19 +08:00
parent 0f7f60e3ff
commit 79109c61eb
5 changed files with 27 additions and 13 deletions

View File

@@ -96,7 +96,9 @@ pub fn decrypt_single(path: &PathBuf, pin: &Option<String>, slot: &Option<String
let mut file_out = File::create(path_out)?;
let start = Instant::now();
util_msg::print_lastline(&format!("Decrypting file: {}{} ...", path_display, iff!(meta.compress, " [compressed]", "")));
util_msg::print_lastline(
&format!("Decrypting file: {}{} ...", path_display, iff!(meta.compress, " [compressed]", ""))
);
let _ = decrypt_file(&mut file_in, &mut file_out, &key, &nonce, meta.compress)?;
util_msg::clear_lastline();
let encrypt_duration = start.elapsed();
@@ -155,7 +157,9 @@ fn try_decrypt_key(envelop: &TinyEncryptEnvelop, pin: &Option<String>, slot: &Op
match envelop.r#type {
TinyEncryptEnvelopType::Pgp => try_decrypt_key_pgp(envelop, pin),
TinyEncryptEnvelopType::Ecdh => try_decrypt_key_ecdh(envelop, pin, slot),
unknown_type => return simple_error!("Unknown or not supported type: {}", unknown_type.get_name())
unknown_type => {
return simple_error!("Unknown or not supported type: {}", unknown_type.get_name());
}
}
}
@@ -166,7 +170,7 @@ fn try_decrypt_key_ecdh(envelop: &TinyEncryptEnvelop, pin: &Option<String>, slot
}
let e_pub_key = &wrap_key.header.e_pub_key;
let e_pub_key_bytes = opt_result!(util::decode_base64_url_no_pad(e_pub_key), "Invalid envelop: {}");
let (_, subject_public_key_info) = opt_result!( SubjectPublicKeyInfo::from_der(&e_pub_key_bytes), "Invalid envelop: {}");
let (_, subject_public_key_info) = opt_result!(SubjectPublicKeyInfo::from_der(&e_pub_key_bytes), "Invalid envelop: {}");
let slot = read_slot(slot)?;
let pin = read_pin(pin);