feat: v0.1.0, encrypt works

This commit is contained in:
2023-09-30 19:43:29 +08:00
parent c317a80119
commit 712e50319a
11 changed files with 143 additions and 35 deletions

View File

@@ -1,8 +1,9 @@
use std::cmp::Ordering;
use std::collections::HashMap;
use std::fs;
use rust_util::{debugging, opt_result, simple_error, XResult};
use rust_util::util_file::resolve_file_path;
use serde::{Deserialize, Serialize};
use crate::spec::TinyEncryptEnvelopType;
@@ -15,7 +16,7 @@ use crate::spec::TinyEncryptEnvelopType;
/// "type": "pgp",
/// "kid": "KID-1",
/// "desc": "this is key 001",
/// "public_key": "----- BEGIN OPENPGP ..."
/// "publicPart": "----- BEGIN OPENPGP ..."
/// },
/// {
/// "type": "ecdh",
@@ -71,10 +72,17 @@ impl TinyEncryptConfig {
});
}
}
let envelops: Vec<_> = matched_envelops_map.values().map(|envelop| *envelop).collect();
let mut envelops: Vec<_> = matched_envelops_map.values().map(|envelop| *envelop).collect();
if envelops.is_empty() {
return simple_error!("Profile: {} has no valid envelopes found", profile);
}
envelops.sort_by(|e1, e2| {
if e1.r#type < e2.r#type { return Ordering::Less; }
if e1.r#type > e2.r#type { return Ordering::Greater; }
if e1.kid < e2.kid { return Ordering::Less; }
if e1.kid > e2.kid { return Ordering::Greater; }
Ordering::Equal
});
debugging!("Found envelopes: {:#?}", envelops);
Ok(envelops)
}