feat: optimize code
This commit is contained in:
@@ -30,10 +30,10 @@ use crate::crypto_cryptor::{Cryptor, KeyNonce};
|
|||||||
use crate::spec::{EncEncryptedMeta, TinyEncryptEnvelop, TinyEncryptEnvelopType, TinyEncryptMeta};
|
use crate::spec::{EncEncryptedMeta, TinyEncryptEnvelop, TinyEncryptEnvelopType, TinyEncryptMeta};
|
||||||
use crate::util::SecVec;
|
use crate::util::SecVec;
|
||||||
use crate::util_digest::DigestWrite;
|
use crate::util_digest::DigestWrite;
|
||||||
#[cfg(feature = "macos")]
|
|
||||||
use crate::util_keychainstatic;
|
|
||||||
#[cfg(feature = "secure-enclave")]
|
#[cfg(feature = "secure-enclave")]
|
||||||
use crate::util_keychainkey;
|
use crate::util_keychainkey;
|
||||||
|
#[cfg(feature = "macos")]
|
||||||
|
use crate::util_keychainstatic;
|
||||||
use crate::util_progress::Progress;
|
use crate::util_progress::Progress;
|
||||||
use crate::wrap_key::WrapKey;
|
use crate::wrap_key::WrapKey;
|
||||||
|
|
||||||
@@ -432,18 +432,18 @@ pub fn try_decrypt_key(config: &Option<TinyEncryptConfig>,
|
|||||||
pin: &Option<String>,
|
pin: &Option<String>,
|
||||||
slot: &Option<String>) -> XResult<Vec<u8>> {
|
slot: &Option<String>) -> XResult<Vec<u8>> {
|
||||||
match envelop.r#type {
|
match envelop.r#type {
|
||||||
TinyEncryptEnvelopType::PgpRsa => try_decrypt_key_pgp(envelop, pin),
|
TinyEncryptEnvelopType::PgpRsa => try_decrypt_key_pgp_rsa(envelop, pin),
|
||||||
TinyEncryptEnvelopType::PgpX25519 => try_decrypt_key_ecdh_pgp_x25519(envelop, pin),
|
TinyEncryptEnvelopType::PgpX25519 => try_decrypt_key_ecdh_pgp_x25519(envelop, pin),
|
||||||
#[cfg(feature = "macos")]
|
#[cfg(feature = "macos")]
|
||||||
TinyEncryptEnvelopType::StaticX25519 => try_decrypt_key_ecdh_static_x25519(config, envelop),
|
TinyEncryptEnvelopType::StaticX25519 => try_decrypt_key_ecdh_static_x25519(config, envelop),
|
||||||
TinyEncryptEnvelopType::PivP256 | TinyEncryptEnvelopType::PivP384 => try_decrypt_key_ecdh(config, envelop, pin, slot),
|
TinyEncryptEnvelopType::PivP256 | TinyEncryptEnvelopType::PivP384 => try_decrypt_piv_key_ecdh(config, envelop, pin, slot),
|
||||||
#[cfg(feature = "secure-enclave")]
|
#[cfg(feature = "secure-enclave")]
|
||||||
TinyEncryptEnvelopType::KeyP256 => try_decrypt_se_key_ecdh(config, envelop),
|
TinyEncryptEnvelopType::KeyP256 => try_decrypt_se_key_ecdh(config, envelop),
|
||||||
unknown_type => simple_error!("Unknown or unsupported type: {}", unknown_type.get_name()),
|
unknown_type => simple_error!("Unknown or unsupported type: {}", unknown_type.get_name()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_decrypt_key_ecdh(config: &Option<TinyEncryptConfig>,
|
fn try_decrypt_piv_key_ecdh(config: &Option<TinyEncryptConfig>,
|
||||||
envelop: &TinyEncryptEnvelop,
|
envelop: &TinyEncryptEnvelop,
|
||||||
pin: &Option<String>,
|
pin: &Option<String>,
|
||||||
slot: &Option<String>) -> XResult<Vec<u8>> {
|
slot: &Option<String>) -> XResult<Vec<u8>> {
|
||||||
@@ -571,7 +571,7 @@ fn try_decrypt_key_ecdh_static_x25519(config: &Option<TinyEncryptConfig>, envelo
|
|||||||
Ok(decrypted_key)
|
Ok(decrypted_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_decrypt_key_pgp(envelop: &TinyEncryptEnvelop, pin: &Option<String>) -> XResult<Vec<u8>> {
|
fn try_decrypt_key_pgp_rsa(envelop: &TinyEncryptEnvelop, pin: &Option<String>) -> XResult<Vec<u8>> {
|
||||||
let mut pgp = util_pgp::get_openpgp()?;
|
let mut pgp = util_pgp::get_openpgp()?;
|
||||||
let mut trans = opt_result!(pgp.transaction(), "Connect OpenPGP card failed: {}");
|
let mut trans = opt_result!(pgp.transaction(), "Connect OpenPGP card failed: {}");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user