feat: update info

This commit is contained in:
2023-09-06 00:34:26 +08:00
parent d1d5c166de
commit d96ebdd5ba
6 changed files with 80 additions and 57 deletions

View File

@@ -2,18 +2,6 @@ use serde::{Deserialize, Serialize};
pub const TINY_ENCRYPT_VERSION: &'static str = "1.0";
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TinyEncryptConfig {
// card cli is not used by tiny-encrypt-rs
pub card_cli: String,
pub default_key_name: String,
pub local_private_key_pem_challenge: String,
pub local_private_key_pem_encrypted: String,
pub local_public_key_pem: String,
pub pgp_encrypt_public_key_pem: Option<String>,
}
/// Specification: [Tiny Encrypt Spec V1.1](https://git.hatter.ink/hatter/tiny-encrypt-java/src/branch/master/TinyEncryptSpecV1.1.md)
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
@@ -33,7 +21,7 @@ pub struct TinyEncryptMeta {
pub ecdh_point: Option<String>,
pub envelop: Option<String>,
// ---------------------------------------
pub envelops: Vec<TinyEncryptEnvelop>,
pub envelops: Option<Vec<TinyEncryptEnvelop>>,
pub encryption_algorithm: Option<String>,
pub nonce: String,
pub file_length: u64,
@@ -60,6 +48,9 @@ pub enum TinyEncryptEnvelopType {
impl TinyEncryptMeta {
pub fn normalize(&mut self) {
if self.envelops.is_none() {
self.envelops = Some(vec![]);
}
self.normalize_ppg_envelop();
self.normalize_age_envelop();
self.normalize_ecdh_envelop();
@@ -67,8 +58,9 @@ impl TinyEncryptMeta {
}
fn normalize_ppg_envelop(&mut self) {
if let (Some(pgp_envelop), Some(pgp_fingerprint)) = (&self.pgp_envelop, &self.pgp_fingerprint) {
self.envelops.push(TinyEncryptEnvelop {
if let (Some(pgp_envelop), Some(pgp_fingerprint), Some(envelops))
= (&self.pgp_envelop, &self.pgp_fingerprint, &mut self.envelops) {
envelops.push(TinyEncryptEnvelop {
r#type: "pgp".to_string(),
kid: pgp_fingerprint.into(),
desc: None,
@@ -80,8 +72,9 @@ impl TinyEncryptMeta {
}
fn normalize_age_envelop(&mut self) {
if let (Some(age_envelop), Some(age_recipient)) = (&self.age_envelop, &self.age_recipient) {
self.envelops.push(TinyEncryptEnvelop {
if let (Some(age_envelop), Some(age_recipient), Some(envelops))
= (&self.age_envelop, &self.age_recipient, &mut self.envelops) {
envelops.push(TinyEncryptEnvelop {
r#type: "age".to_string(),
kid: age_recipient.into(),
desc: None,
@@ -93,8 +86,9 @@ impl TinyEncryptMeta {
}
fn normalize_ecdh_envelop(&mut self) {
if let (Some(ecdh_envelop), Some(ecdh_point)) = (&self.ecdh_envelop, &self.ecdh_point) {
self.envelops.push(TinyEncryptEnvelop {
if let (Some(ecdh_envelop), Some(ecdh_point), Some(envelops))
= (&self.ecdh_envelop, &self.ecdh_point, &mut self.envelops) {
envelops.push(TinyEncryptEnvelop {
r#type: "ecdh".to_string(),
kid: ecdh_point.into(),
desc: None,
@@ -106,10 +100,10 @@ impl TinyEncryptMeta {
}
fn normalize_envelop(&mut self) {
if let Some(envelop) = &self.envelop {
self.envelops.push(TinyEncryptEnvelop {
if let (Some(envelop), Some(envelops)) = (&self.envelop, &mut self.envelops) {
envelops.push(TinyEncryptEnvelop {
r#type: "kms".to_string(),
kid: "#default".into(),
kid: "".into(),
desc: None,
encrypted_key: envelop.into(),
});
@@ -117,29 +111,3 @@ impl TinyEncryptMeta {
}
}
}
pub fn get_user_agent() -> String {
format!("TinyEncrypt-rs v{}@{}", env!("CARGO_PKG_VERSION"),
if cfg!(target_os = "macos") {
"MacOS"
} else if cfg!(target_os = "ios") {
"iOS"
} else if cfg!(target_os = "android") {
"Android"
} else if cfg!(target_os = "windows") {
"Windows"
} else if cfg!(target_os = "linux") {
"Linux"
} else if cfg!(target_os = "freebsd") {
"FreeBSD"
} else if cfg!(target_os = "dragonfly") {
"Dragonfly"
} else if cfg!(target_os = "openbsd") {
"OpenBSD"
} else if cfg!(target_os = "netbsd") {
"NetBSD"
} else {
panic!("Unsupported OS!");
}
)
}