From 115e0f70949002d40cdfb623620f5a19f83fddcf Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 9 Dec 2023 18:53:33 +0800 Subject: [PATCH] feat: v1.2.1, optimize naming --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/cmd_decrypt.rs | 4 ++-- src/cmd_encrypt.rs | 4 ++-- src/spec.rs | 36 ++++++++++++++++++------------------ 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d9f10b5..f551f98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1700,7 +1700,7 @@ dependencies = [ [[package]] name = "tiny-encrypt" -version = "1.2.0" +version = "1.2.1" dependencies = [ "aes-gcm-stream", "base64", diff --git a/Cargo.toml b/Cargo.toml index f6613e3..81a74a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tiny-encrypt" -version = "1.2.0" +version = "1.2.1" edition = "2021" license = "MIT" description = "A simple and tiny file encrypt tool" diff --git a/src/cmd_decrypt.rs b/src/cmd_decrypt.rs index 524f067..1ed625c 100644 --- a/src/cmd_decrypt.rs +++ b/src/cmd_decrypt.rs @@ -432,11 +432,11 @@ pub fn try_decrypt_key(config: &Option, pin: &Option, slot: &Option) -> XResult> { match envelop.r#type { - TinyEncryptEnvelopType::Pgp => try_decrypt_key_pgp(envelop, pin), + TinyEncryptEnvelopType::PgpRsa => try_decrypt_key_pgp(envelop, pin), TinyEncryptEnvelopType::PgpX25519 => try_decrypt_key_ecdh_pgp_x25519(envelop, pin), #[cfg(feature = "macos")] TinyEncryptEnvelopType::StaticX25519 => try_decrypt_key_ecdh_static_x25519(config, envelop), - TinyEncryptEnvelopType::Ecdh | TinyEncryptEnvelopType::EcdhP384 => try_decrypt_key_ecdh(config, envelop, pin, slot), + TinyEncryptEnvelopType::PivP256 | TinyEncryptEnvelopType::EcdhP384 => try_decrypt_key_ecdh(config, envelop, pin, slot), #[cfg(feature = "secure-enclave")] TinyEncryptEnvelopType::KeyP256 => try_decrypt_se_key_ecdh(config, envelop), unknown_type => simple_error!("Unknown or unsupported type: {}", unknown_type.get_name()), diff --git a/src/cmd_encrypt.rs b/src/cmd_encrypt.rs index e58a23c..e7db828 100644 --- a/src/cmd_encrypt.rs +++ b/src/cmd_encrypt.rs @@ -265,13 +265,13 @@ fn encrypt_envelops(cryptor: Cryptor, key: &[u8], envelops: &[&TinyEncryptConfig let mut encrypted_envelops = vec![]; for envelop in envelops { match envelop.r#type { - TinyEncryptEnvelopType::Pgp => { + TinyEncryptEnvelopType::PgpRsa => { encrypted_envelops.push(encrypt_envelop_pgp(key, envelop)?); } TinyEncryptEnvelopType::PgpX25519 | TinyEncryptEnvelopType::StaticX25519 => { encrypted_envelops.push(encrypt_envelop_ecdh_x25519(cryptor, key, envelop)?); } - TinyEncryptEnvelopType::Ecdh | TinyEncryptEnvelopType::KeyP256 => { + TinyEncryptEnvelopType::PivP256 | TinyEncryptEnvelopType::KeyP256 => { encrypted_envelops.push(encrypt_envelop_ecdh(cryptor, key, envelop)?); } TinyEncryptEnvelopType::EcdhP384 => { diff --git a/src/spec.rs b/src/spec.rs index 2284a72..ea55f8b 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -65,26 +65,26 @@ pub struct TinyEncryptEnvelop { /// NOTICE: Kms and Age is not being supported in the future #[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, PartialOrd)] pub enum TinyEncryptEnvelopType { - // OpenPGP RSA - #[serde(rename = "pgp")] - Pgp, - // OpenPGP X25519 + // OpenPGP Card RSA + #[serde(rename = "pgp-rsa", alias = "pgp")] + PgpRsa, + // OpenPGP Card X25519 #[serde(rename = "pgp-x25519")] PgpX25519, - // Static X25519 (less secure) + // Keychain Static X25519 (less secure) #[serde(rename = "static-x25519")] StaticX25519, - // Key P256 (Private key in Secure Enclave) + // Secure Enclave ECDH P256 #[serde(rename = "key-p256")] KeyP256, // Age, tiny-encrypt-rs is not supported #[serde(rename = "age")] Age, - // ECDH P256 - #[serde(rename = "ecdh")] - Ecdh, - // ECDH P384 - #[serde(rename = "ecdh-p384")] + // PIV ECDH P256 + #[serde(rename = "piv-p256", alias = "ecdh")] + PivP256, + // PIV ECDH P384 + #[serde(rename = "piv-p384", alias = "ecdh-p384")] EcdhP384, // KMS, tiny-encrypt-rs is not supported #[serde(rename = "kms")] @@ -98,25 +98,25 @@ impl TinyEncryptEnvelopType { pub fn get_name(&self) -> &'static str { match self { - TinyEncryptEnvelopType::Pgp => "pgp", + TinyEncryptEnvelopType::PgpRsa => "pgp-rsa", TinyEncryptEnvelopType::PgpX25519 => "pgp-x25519", TinyEncryptEnvelopType::StaticX25519 => "static-x25519", TinyEncryptEnvelopType::KeyP256 => "key-p256", TinyEncryptEnvelopType::Age => "age", - TinyEncryptEnvelopType::Ecdh => "ecdh", - TinyEncryptEnvelopType::EcdhP384 => "ecdh-p384", + TinyEncryptEnvelopType::PivP256 => "piv-p256", + TinyEncryptEnvelopType::EcdhP384 => "piv-p384", TinyEncryptEnvelopType::Kms => "kms", } } pub fn auto_select(&self) -> bool { match self { - TinyEncryptEnvelopType::Pgp => false, + TinyEncryptEnvelopType::PgpRsa => false, TinyEncryptEnvelopType::PgpX25519 => false, TinyEncryptEnvelopType::StaticX25519 => true, TinyEncryptEnvelopType::KeyP256 => true, TinyEncryptEnvelopType::Age => false, - TinyEncryptEnvelopType::Ecdh => false, + TinyEncryptEnvelopType::PivP256 => false, TinyEncryptEnvelopType::EcdhP384 => false, TinyEncryptEnvelopType::Kms => true, } @@ -215,7 +215,7 @@ impl TinyEncryptMeta { if let (Some(pgp_envelop), Some(pgp_fingerprint), Some(envelops)) = (&self.pgp_envelop, &self.pgp_fingerprint, &mut self.envelops) { envelops.push(TinyEncryptEnvelop { - r#type: TinyEncryptEnvelopType::Pgp, + r#type: TinyEncryptEnvelopType::PgpRsa, kid: pgp_fingerprint.into(), desc: None, encrypted_key: pgp_envelop.into(), @@ -243,7 +243,7 @@ impl TinyEncryptMeta { if let (Some(ecdh_envelop), Some(ecdh_point), Some(envelops)) = (&self.ecdh_envelop, &self.ecdh_point, &mut self.envelops) { envelops.push(TinyEncryptEnvelop { - r#type: TinyEncryptEnvelopType::Ecdh, + r#type: TinyEncryptEnvelopType::PivP256, kid: ecdh_point.into(), desc: None, encrypted_key: ecdh_envelop.into(),