feat: find kid first arg
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# tiny-encrypt-rs
|
# tiny-encrypt-rs
|
||||||
|
|
||||||
**IMPORTANT**: To use tiny-encrypt, a Yubikey(https://www.yubico.com/products/) or CanoKey(https://www.canokeys.org/) is
|
**IMPORTANT**: To use tiny-encrypt, a Yubikey(https://www.yubico.com/products/) is
|
||||||
required, the Key NEED supports PIV or OpenPGP.
|
required, the key MUST support PIV or OpenPGP.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ Encrypt config `~/.tinyencrypt/config-rs.json`:
|
|||||||
"KID-1",
|
"KID-1",
|
||||||
"KID-2"
|
"KID-2"
|
||||||
],
|
],
|
||||||
"leve2": [
|
"l2,leve2": [
|
||||||
"KID-2"
|
"KID-2"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -270,15 +270,11 @@ fn read_slot(config: &Option<TinyEncryptConfig>, kid: &str, slot: &Option<String
|
|||||||
Some(slot) => Ok(slot.to_string()),
|
Some(slot) => Ok(slot.to_string()),
|
||||||
None => {
|
None => {
|
||||||
if let Some(config) = config {
|
if let Some(config) = config {
|
||||||
if let Some(e) = config.find_by_kid(kid) {
|
if let Some(first_arg) = config.find_first_arg_by_kid(kid) {
|
||||||
if let Some(args) = &e.args {
|
|
||||||
if let Some(first_arg) = args.iter().next() {
|
|
||||||
information!("Found kid: {}'s slot: {}", kid, first_arg);
|
information!("Found kid: {}'s slot: {}", kid, first_arg);
|
||||||
return Ok(first_arg.to_string());
|
return Ok(first_arg.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
print!("Input slot(eg 82, 83 ...): ");
|
print!("Input slot(eg 82, 83 ...): ");
|
||||||
io::stdout().flush().ok();
|
io::stdout().flush().ok();
|
||||||
let mut buff = String::new();
|
let mut buff = String::new();
|
||||||
|
|||||||
@@ -72,6 +72,14 @@ impl TinyEncryptConfig {
|
|||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn find_first_arg_by_kid(&self, kid: &str) -> Option<&String> {
|
||||||
|
self.find_args_by_kid(kid).map(|a| a.iter().next()).flatten()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn find_args_by_kid(&self, kid: &str) -> Option<&Vec<String>> {
|
||||||
|
self.find_by_kid(kid).map(|e| e.args.as_ref()).flatten()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn find_by_kid(&self, kid: &str) -> Option<&TinyEncryptConfigEnvelop> {
|
pub fn find_by_kid(&self, kid: &str) -> Option<&TinyEncryptConfigEnvelop> {
|
||||||
self.envelops.iter().find(|e| e.kid == kid)
|
self.envelops.iter().find(|e| e.kid == kid)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user