Minor error handling/messaging cleanups.
This commit is contained in:
parent
576110ecce
commit
9739074b63
4 changed files with 14 additions and 9 deletions
|
@ -2,6 +2,7 @@
|
|||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||
|
||||
use anyhow::Result;
|
||||
use std::convert::TryFrom;
|
||||
use std::str::FromStr;
|
||||
use std::string::FromUtf8Error;
|
||||
use thiserror;
|
||||
|
@ -229,7 +230,7 @@ pub fn test_keygen(
|
|||
// Generate all three subkeys on card
|
||||
let algo = param[0];
|
||||
|
||||
let alg = AlgoSimple::from(algo);
|
||||
let alg = AlgoSimple::try_from(algo)?;
|
||||
|
||||
println!(" Generate subkey for Signing");
|
||||
let (pkm, ts) =
|
||||
|
|
|
@ -36,11 +36,13 @@ pub enum AlgoSimple {
|
|||
Curve25519,
|
||||
}
|
||||
|
||||
impl From<&str> for AlgoSimple {
|
||||
fn from(algo: &str) -> Self {
|
||||
impl TryFrom<&str> for AlgoSimple {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(algo: &str) -> Result<Self, anyhow::Error> {
|
||||
use AlgoSimple::*;
|
||||
|
||||
match algo {
|
||||
Ok(match algo {
|
||||
"RSA1k/17" => RSA1k(17),
|
||||
"RSA1k/32" => RSA1k(32),
|
||||
"RSA2k/17" => RSA2k(17),
|
||||
|
@ -53,8 +55,8 @@ impl From<&str> for AlgoSimple {
|
|||
"NIST384" => NIST384,
|
||||
"NIST521" => NIST521,
|
||||
"Curve25519" => Curve25519,
|
||||
_ => panic!("unexpected algo {}", algo),
|
||||
}
|
||||
_ => return Err(anyhow!("unexpected algo {}", algo)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ pub enum Hash<'a> {
|
|||
}
|
||||
|
||||
impl Hash<'_> {
|
||||
/// This fn is currently only used in the context of creating a
|
||||
/// digestinfo for SHA*. Other OIDs are not implemented.
|
||||
pub(crate) fn oid(&self) -> Option<&'static [u8]> {
|
||||
match self {
|
||||
Self::SHA256(_) => {
|
||||
|
@ -33,8 +35,8 @@ impl Hash<'_> {
|
|||
Self::SHA512(_) => {
|
||||
Some(&[0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03])
|
||||
}
|
||||
Self::EdDSA(_) => panic!("This should not be called"),
|
||||
Self::ECDSA(_) => panic!("This should not be called"),
|
||||
Self::EdDSA(_) => panic!("OIDs for EdDSA are unimplemented"),
|
||||
Self::ECDSA(_) => panic!("OIDs for ECDSA are unimplemented"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -464,7 +464,7 @@ fn generate_keys(
|
|||
Some("nistp384") => vec![AlgoSimple::NIST384],
|
||||
Some("nistp521") => vec![AlgoSimple::NIST521],
|
||||
Some("25519") => vec![AlgoSimple::Curve25519],
|
||||
_ => unimplemented!("unexpected algorithm"),
|
||||
_ => return Err(anyhow!("Unexpected algorithm")),
|
||||
};
|
||||
|
||||
log::info!(
|
||||
|
|
Loading…
Reference in a new issue