feat: v1.11.8, add keypair-keychain-import/export

This commit is contained in:
2025-03-26 23:37:21 +08:00
parent 3fb43403aa
commit 070161c056
6 changed files with 98 additions and 23 deletions

View File

@@ -33,12 +33,6 @@ impl Command for CommandImpl {
.takes_value(true)
.help("Key chain name"),
)
.arg(
Arg::with_name("import-key-value")
.long("import-key-value")
.takes_value(true)
.help("Import key value"),
)
.arg(Arg::with_name("json").long("json").help("JSON output"))
}
@@ -46,26 +40,12 @@ impl Command for CommandImpl {
let with_hmac_encrypt = sub_arg_matches.is_present("with-hmac-encrypt");
let key_type = sub_arg_matches.value_of("type").unwrap().to_lowercase();
let keychain_name = sub_arg_matches.value_of("keychain-name");
let import_key_value = sub_arg_matches.value_of("import-key-value");
if let Some(keychain_name) = keychain_name {
let keychain_key = KeychainKey::from_key_name_default(keychain_name);
if let Some(keychain_key_value_bytes) = keychain_key.get_password()? {
let keychain_key_value: KeychainKeyValue =
serde_json::from_slice(&keychain_key_value_bytes)?;
util_msg::set_logger_std_out(false);
information!("Keychain key URI: {}", keychain_key.to_key_uri());
println!(
"{}",
serde_json::to_string_pretty(&keychain_key_value).unwrap()
);
if let Some(_) = keychain_key.get_password()? {
return simple_error!("Keychain key URI: {} exists", keychain_key.to_key_uri());
}
if let Some(import_key_value) = import_key_value {
keychain_key.set_password(import_key_value.as_bytes())?;
return Ok(None);
}
}
let json_output = sub_arg_matches.is_present("json");