-
Notifications
You must be signed in to change notification settings - Fork 68
/
keyring.rs
36 lines (30 loc) · 1.07 KB
/
keyring.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//! ECDSA keyring.
use crate::{Algorithm, Error, KeyHandle, LoadPkcs8, Result};
#[cfg(feature = "nistp256")]
use super::nistp256;
#[cfg(feature = "secp256k1")]
use super::secp256k1;
/// ECDSA keyring.
#[derive(Debug, Default)]
pub struct KeyRing {
/// ECDSA/P-256 keys.
#[cfg(feature = "nistp256")]
#[cfg_attr(docsrs, doc(cfg(feature = "nistp256")))]
pub nistp256: nistp256::KeyRing,
/// ECDSA/secp256k1 keys.
#[cfg(feature = "secp256k1")]
#[cfg_attr(docsrs, doc(cfg(feature = "secp256k1")))]
pub secp256k1: secp256k1::KeyRing,
}
impl LoadPkcs8 for KeyRing {
fn load_pkcs8(&mut self, private_key: pkcs8::PrivateKeyInfo<'_>) -> Result<KeyHandle> {
match Algorithm::try_from(private_key.algorithm)? {
#[cfg(feature = "nistp256")]
Algorithm::EcdsaNistP256 => self.nistp256.load_pkcs8(private_key),
#[cfg(feature = "secp256k1")]
Algorithm::EcdsaSecp256k1 => self.secp256k1.load_pkcs8(private_key),
#[allow(unreachable_patterns)]
_ => Err(Error::AlgorithmInvalid),
}
}
}