feat: v1.7.0, support GPG encrypt and decrypt
This commit is contained in:
@@ -10,7 +10,7 @@ use rsa::Pkcs1v15Encrypt;
|
||||
use rust_util::{debugging, failure, iff, information, opt_result, simple_error, success, util_size, XResult};
|
||||
use rust_util::util_time::UnixEpochTime;
|
||||
|
||||
use crate::{crypto_cryptor, crypto_simple, util, util_enc_file, util_env};
|
||||
use crate::{crypto_cryptor, crypto_simple, util, util_enc_file, util_env, util_gpg};
|
||||
use crate::compress::GzStreamEncoder;
|
||||
use crate::config::{TinyEncryptConfig, TinyEncryptConfigEnvelop};
|
||||
use crate::consts::{
|
||||
@@ -23,13 +23,13 @@ use crate::consts::{
|
||||
SALT_COMMENT, TINY_ENC_CONFIG_FILE, TINY_ENC_FILE_EXT,
|
||||
};
|
||||
use crate::crypto_cryptor::{Cryptor, KeyNonce};
|
||||
use crate::util_rsa;
|
||||
use crate::spec::{
|
||||
EncEncryptedMeta, EncMetadata,
|
||||
TinyEncryptEnvelop, TinyEncryptEnvelopType, TinyEncryptMeta,
|
||||
};
|
||||
use crate::util_ecdh::{ecdh_kyber1024, ecdh_p256, ecdh_p384, ecdh_x25519};
|
||||
use crate::util_progress::Progress;
|
||||
use crate::util_rsa;
|
||||
use crate::wrap_key::{WrapKey, WrapKeyHeader};
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
@@ -284,6 +284,9 @@ fn encrypt_envelops(cryptor: Cryptor, key: &[u8], envelops: &[&TinyEncryptConfig
|
||||
TinyEncryptEnvelopType::PgpRsa | TinyEncryptEnvelopType::PivRsa => {
|
||||
encrypted_envelops.push(encrypt_envelop_rsa(key, envelop)?);
|
||||
}
|
||||
TinyEncryptEnvelopType::Gpg => {
|
||||
encrypted_envelops.push(encrypt_envelop_gpg(key, envelop)?);
|
||||
}
|
||||
TinyEncryptEnvelopType::PgpX25519 | TinyEncryptEnvelopType::StaticX25519 => {
|
||||
encrypted_envelops.push(encrypt_envelop_ecdh_x25519(cryptor, key, envelop)?);
|
||||
}
|
||||
@@ -382,6 +385,16 @@ fn encrypt_envelop_rsa(key: &[u8], envelop: &TinyEncryptConfigEnvelop) -> XResul
|
||||
})
|
||||
}
|
||||
|
||||
fn encrypt_envelop_gpg(key: &[u8], envelop: &TinyEncryptConfigEnvelop) -> XResult<TinyEncryptEnvelop> {
|
||||
let encrypted_key = opt_result!(util_gpg::gpg_encrypt(&envelop.public_part, key), "GPG encrypt failed: {}");
|
||||
Ok(TinyEncryptEnvelop {
|
||||
r#type: envelop.r#type,
|
||||
kid: envelop.kid.clone(),
|
||||
desc: None,
|
||||
encrypted_key,
|
||||
})
|
||||
}
|
||||
|
||||
fn get_compress_level(cmd_encrypt: &CmdEncrypt) -> Option<u32> {
|
||||
if cmd_encrypt.compress || util_env::get_default_compress().unwrap_or(false) {
|
||||
Some(cmd_encrypt.compress_level.unwrap_or_else(|| Compression::default().level()))
|
||||
|
||||
Reference in New Issue
Block a user