keymgr: Make the return value of generate() indicate if a new key was created.
This commit is contained in:
parent
44f6d1c827
commit
249149d4ce
|
@ -50,21 +50,23 @@ impl KeyMgr {
|
||||||
///
|
///
|
||||||
/// If the key already exists in the specified key store, the `overwrite` flag is used to
|
/// If the key already exists in the specified key store, the `overwrite` flag is used to
|
||||||
/// decide whether to overwrite it with a newly generated key.
|
/// decide whether to overwrite it with a newly generated key.
|
||||||
|
///
|
||||||
|
/// Returns `Ok(Some(())` if a new key was created, and `Ok(None)` otherwise.
|
||||||
pub fn generate<K: ToEncodableKey>(
|
pub fn generate<K: ToEncodableKey>(
|
||||||
&self,
|
&self,
|
||||||
key_spec: &dyn KeySpecifier,
|
key_spec: &dyn KeySpecifier,
|
||||||
selector: KeystoreSelector,
|
selector: KeystoreSelector,
|
||||||
rng: &mut dyn KeygenRng,
|
rng: &mut dyn KeygenRng,
|
||||||
overwrite: bool,
|
overwrite: bool,
|
||||||
) -> Result<()> {
|
) -> Result<Option<()>> {
|
||||||
let store = self.select_keystore(&selector)?;
|
let store = self.select_keystore(&selector)?;
|
||||||
let key_type = K::Key::key_type();
|
let key_type = K::Key::key_type();
|
||||||
|
|
||||||
if overwrite || !store.contains(key_spec, key_type)? {
|
if overwrite || !store.contains(key_spec, key_type)? {
|
||||||
let key = K::Key::generate(rng)?;
|
let key = K::Key::generate(rng)?;
|
||||||
store.insert(&key, key_spec, key_type)
|
store.insert(&key, key_spec, key_type).map(Some)
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue