use archon_core::hexbytes::to_hex;
use archon_core::keycodec::pubkey_to_spki_pem;
use archon_core::keytext::encode_key;
pub enum PubFormat {
Spki,
Text,
Hex,
}
impl PubFormat {
pub fn name(&self) -> &'static str {
match self {
PubFormat::Spki => "spki",
PubFormat::Text => "text",
PubFormat::Hex => "hex",
}
}
}
pub fn parse_pub_format(s: &str) -> Result<PubFormat, String> {
match s {
"spki" => Ok(PubFormat::Spki),
"text" => Ok(PubFormat::Text),
"hex" => Ok(PubFormat::Hex),
other => Err(format!("unknown --format {other:?} (want spki|text|hex)")),
}
}
pub fn render_pubkey(pk: &[u8], fmt: &PubFormat) -> Result<String, String> {
match fmt {
PubFormat::Spki => pubkey_to_spki_pem(pk),
PubFormat::Text => Ok(format!("{}\n", encode_key(pk))),
PubFormat::Hex => Ok(format!("{}\n", to_hex(pk))),
}
}