feat: v1.2.1, optimize naming

This commit is contained in:
2023-12-09 18:53:33 +08:00
parent d75a88c90c
commit 115e0f7094
5 changed files with 24 additions and 24 deletions

2
Cargo.lock generated
View File

@@ -1700,7 +1700,7 @@ dependencies = [
[[package]] [[package]]
name = "tiny-encrypt" name = "tiny-encrypt"
version = "1.2.0" version = "1.2.1"
dependencies = [ dependencies = [
"aes-gcm-stream", "aes-gcm-stream",
"base64", "base64",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "tiny-encrypt" name = "tiny-encrypt"
version = "1.2.0" version = "1.2.1"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"
description = "A simple and tiny file encrypt tool" description = "A simple and tiny file encrypt tool"

View File

@@ -432,11 +432,11 @@ 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::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), 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::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")] #[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()),

View File

@@ -265,13 +265,13 @@ fn encrypt_envelops(cryptor: Cryptor, key: &[u8], envelops: &[&TinyEncryptConfig
let mut encrypted_envelops = vec![]; let mut encrypted_envelops = vec![];
for envelop in envelops { for envelop in envelops {
match envelop.r#type { match envelop.r#type {
TinyEncryptEnvelopType::Pgp => { TinyEncryptEnvelopType::PgpRsa => {
encrypted_envelops.push(encrypt_envelop_pgp(key, envelop)?); encrypted_envelops.push(encrypt_envelop_pgp(key, envelop)?);
} }
TinyEncryptEnvelopType::PgpX25519 | TinyEncryptEnvelopType::StaticX25519 => { TinyEncryptEnvelopType::PgpX25519 | TinyEncryptEnvelopType::StaticX25519 => {
encrypted_envelops.push(encrypt_envelop_ecdh_x25519(cryptor, key, envelop)?); 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)?); encrypted_envelops.push(encrypt_envelop_ecdh(cryptor, key, envelop)?);
} }
TinyEncryptEnvelopType::EcdhP384 => { TinyEncryptEnvelopType::EcdhP384 => {

View File

@@ -65,26 +65,26 @@ pub struct TinyEncryptEnvelop {
/// NOTICE: Kms and Age is not being supported in the future /// NOTICE: Kms and Age is not being supported in the future
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, PartialOrd)] #[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, PartialOrd)]
pub enum TinyEncryptEnvelopType { pub enum TinyEncryptEnvelopType {
// OpenPGP RSA // OpenPGP Card RSA
#[serde(rename = "pgp")] #[serde(rename = "pgp-rsa", alias = "pgp")]
Pgp, PgpRsa,
// OpenPGP X25519 // OpenPGP Card X25519
#[serde(rename = "pgp-x25519")] #[serde(rename = "pgp-x25519")]
PgpX25519, PgpX25519,
// Static X25519 (less secure) // Keychain Static X25519 (less secure)
#[serde(rename = "static-x25519")] #[serde(rename = "static-x25519")]
StaticX25519, StaticX25519,
// Key P256 (Private key in Secure Enclave) // Secure Enclave ECDH P256
#[serde(rename = "key-p256")] #[serde(rename = "key-p256")]
KeyP256, KeyP256,
// Age, tiny-encrypt-rs is not supported // Age, tiny-encrypt-rs is not supported
#[serde(rename = "age")] #[serde(rename = "age")]
Age, Age,
// ECDH P256 // PIV ECDH P256
#[serde(rename = "ecdh")] #[serde(rename = "piv-p256", alias = "ecdh")]
Ecdh, PivP256,
// ECDH P384 // PIV ECDH P384
#[serde(rename = "ecdh-p384")] #[serde(rename = "piv-p384", alias = "ecdh-p384")]
EcdhP384, EcdhP384,
// KMS, tiny-encrypt-rs is not supported // KMS, tiny-encrypt-rs is not supported
#[serde(rename = "kms")] #[serde(rename = "kms")]
@@ -98,25 +98,25 @@ impl TinyEncryptEnvelopType {
pub fn get_name(&self) -> &'static str { pub fn get_name(&self) -> &'static str {
match self { match self {
TinyEncryptEnvelopType::Pgp => "pgp", TinyEncryptEnvelopType::PgpRsa => "pgp-rsa",
TinyEncryptEnvelopType::PgpX25519 => "pgp-x25519", TinyEncryptEnvelopType::PgpX25519 => "pgp-x25519",
TinyEncryptEnvelopType::StaticX25519 => "static-x25519", TinyEncryptEnvelopType::StaticX25519 => "static-x25519",
TinyEncryptEnvelopType::KeyP256 => "key-p256", TinyEncryptEnvelopType::KeyP256 => "key-p256",
TinyEncryptEnvelopType::Age => "age", TinyEncryptEnvelopType::Age => "age",
TinyEncryptEnvelopType::Ecdh => "ecdh", TinyEncryptEnvelopType::PivP256 => "piv-p256",
TinyEncryptEnvelopType::EcdhP384 => "ecdh-p384", TinyEncryptEnvelopType::EcdhP384 => "piv-p384",
TinyEncryptEnvelopType::Kms => "kms", TinyEncryptEnvelopType::Kms => "kms",
} }
} }
pub fn auto_select(&self) -> bool { pub fn auto_select(&self) -> bool {
match self { match self {
TinyEncryptEnvelopType::Pgp => false, TinyEncryptEnvelopType::PgpRsa => false,
TinyEncryptEnvelopType::PgpX25519 => false, TinyEncryptEnvelopType::PgpX25519 => false,
TinyEncryptEnvelopType::StaticX25519 => true, TinyEncryptEnvelopType::StaticX25519 => true,
TinyEncryptEnvelopType::KeyP256 => true, TinyEncryptEnvelopType::KeyP256 => true,
TinyEncryptEnvelopType::Age => false, TinyEncryptEnvelopType::Age => false,
TinyEncryptEnvelopType::Ecdh => false, TinyEncryptEnvelopType::PivP256 => false,
TinyEncryptEnvelopType::EcdhP384 => false, TinyEncryptEnvelopType::EcdhP384 => false,
TinyEncryptEnvelopType::Kms => true, TinyEncryptEnvelopType::Kms => true,
} }
@@ -215,7 +215,7 @@ impl TinyEncryptMeta {
if let (Some(pgp_envelop), Some(pgp_fingerprint), Some(envelops)) if let (Some(pgp_envelop), Some(pgp_fingerprint), Some(envelops))
= (&self.pgp_envelop, &self.pgp_fingerprint, &mut self.envelops) { = (&self.pgp_envelop, &self.pgp_fingerprint, &mut self.envelops) {
envelops.push(TinyEncryptEnvelop { envelops.push(TinyEncryptEnvelop {
r#type: TinyEncryptEnvelopType::Pgp, r#type: TinyEncryptEnvelopType::PgpRsa,
kid: pgp_fingerprint.into(), kid: pgp_fingerprint.into(),
desc: None, desc: None,
encrypted_key: pgp_envelop.into(), encrypted_key: pgp_envelop.into(),
@@ -243,7 +243,7 @@ impl TinyEncryptMeta {
if let (Some(ecdh_envelop), Some(ecdh_point), Some(envelops)) if let (Some(ecdh_envelop), Some(ecdh_point), Some(envelops))
= (&self.ecdh_envelop, &self.ecdh_point, &mut self.envelops) { = (&self.ecdh_envelop, &self.ecdh_point, &mut self.envelops) {
envelops.push(TinyEncryptEnvelop { envelops.push(TinyEncryptEnvelop {
r#type: TinyEncryptEnvelopType::Ecdh, r#type: TinyEncryptEnvelopType::PivP256,
kid: ecdh_point.into(), kid: ecdh_point.into(),
desc: None, desc: None,
encrypted_key: ecdh_envelop.into(), encrypted_key: ecdh_envelop.into(),