feat: update se-generate
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
use crate::pkiutil::bytes_to_pem;
|
use crate::pkiutil::bytes_to_pem;
|
||||||
use crate::seutil;
|
use crate::seutil;
|
||||||
|
use crate::util::base64_encode;
|
||||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||||
use rust_util::util_clap::{Command, CommandError};
|
use rust_util::util_clap::{Command, CommandError};
|
||||||
use rust_util::util_msg;
|
use rust_util::util_msg;
|
||||||
@@ -46,7 +47,7 @@ impl Command for CommandImpl {
|
|||||||
let sign = match ty {
|
let sign = match ty {
|
||||||
"signing" | "ecsign" | "sign" => true,
|
"signing" | "ecsign" | "sign" => true,
|
||||||
"key_agreement" | "ecdh" | "dh" => false,
|
"key_agreement" | "ecdh" | "dh" => false,
|
||||||
_ => return simple_error!("Invalie type: {}", ty),
|
_ => return simple_error!("Invalid type: {}", ty),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (public_key_point, public_key_der, private_key) =
|
let (public_key_point, public_key_der, private_key) =
|
||||||
@@ -54,17 +55,22 @@ impl Command for CommandImpl {
|
|||||||
|
|
||||||
let public_key_point_hex = hex::encode(&public_key_point);
|
let public_key_point_hex = hex::encode(&public_key_point);
|
||||||
let public_key_pem = bytes_to_pem("PUBLIC KEY", &*public_key_der);
|
let public_key_pem = bytes_to_pem("PUBLIC KEY", &*public_key_der);
|
||||||
let key = format!("key://{}:se/p256:{}:{}",
|
let key = format!(
|
||||||
host, iff!(sign, "signing", "key_agreement"), private_key,
|
"key://{}:se/p256:{}:{}",
|
||||||
|
host,
|
||||||
|
iff!(sign, "signing", "key_agreement"),
|
||||||
|
private_key,
|
||||||
);
|
);
|
||||||
if json_output {
|
if json_output {
|
||||||
let mut json = BTreeMap::<&'_ str, String>::new();
|
let mut json = BTreeMap::<&'_ str, String>::new();
|
||||||
json.insert("public_key_point", public_key_point_hex);
|
json.insert("public_key_point", public_key_point_hex);
|
||||||
json.insert("public_key_pem", public_key_pem);
|
json.insert("public_key_pem", base64_encode(&*public_key_der));
|
||||||
json.insert("key", key);
|
json.insert("key", key);
|
||||||
|
|
||||||
|
println!("{}", serde_json::to_string_pretty(&json).unwrap());
|
||||||
} else {
|
} else {
|
||||||
success!("Public key(point): {}", public_key_point_hex);
|
success!("Public key(point): {}", public_key_point_hex);
|
||||||
success!("Public key PEM: {}", public_key_pem);
|
success!("Public key PEM: \n{}", public_key_pem);
|
||||||
success!("Key: {}", key);
|
success!("Key: {}", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user