signatory: add `FsKeyStore::import`
Support for importing PKCS#8 keys into `KeyRing`s.
//! Filesystem-backed keystore
-use crate::{Error, KeyInfo, KeyName, Result};
+use crate::{Error, KeyInfo, KeyName, KeyRing, LoadPkcs8, Result};
use core::convert::TryInto;
use std::{
fs,
@@ -93,6 +93,11 @@ impl FsKeyStore {
})
}
+ /// Import a key with a given name into the provided keyring.
+ pub fn import(&self, name: &KeyName, key_ring: &mut KeyRing) -> Result<()> {
+ key_ring.load_pkcs8(self.load(name)?.private_key_info())
+ }
+
/// Load a PKCS#8 key from the keystore.
pub fn load(&self, name: &KeyName) -> Result<pkcs8::PrivateKeyDocument> {
Ok(pkcs8::PrivateKeyDocument::read_pem_file(
