pub trait Keystore:
Send
+ Sync
+ 'static {
// Required methods
fn id(&self) -> &KeystoreId;
fn contains(
&self,
key_spec: &dyn KeySpecifier,
item_type: &KeystoreItemType,
) -> Result<bool>;
fn get(
&self,
key_spec: &dyn KeySpecifier,
item_type: &KeystoreItemType,
) -> Result<Option<ErasedKey>>;
fn raw_entry_id(&self, raw_id: &str) -> Result<RawEntryId>;
fn insert(
&self,
key: &dyn EncodableItem,
key_spec: &dyn KeySpecifier,
) -> Result<()>;
fn remove(
&self,
key_spec: &dyn KeySpecifier,
item_type: &KeystoreItemType,
) -> Result<Option<()>>;
fn remove_unchecked(&self, entry_id: &RawEntryId) -> Result<()>;
fn list(&self) -> Result<Vec<KeystoreEntryResult<KeystoreEntry<'_>>>>;
}
keymgr
only.Expand description
A generic key store.
Required Methods§
Sourcefn id(&self) -> &KeystoreId
fn id(&self) -> &KeystoreId
An identifier for this key store instance.
This identifier is used by some KeyMgr
APIs to identify a specific key
store.
Sourcefn contains(
&self,
key_spec: &dyn KeySpecifier,
item_type: &KeystoreItemType,
) -> Result<bool>
fn contains( &self, key_spec: &dyn KeySpecifier, item_type: &KeystoreItemType, ) -> Result<bool>
Check if the key identified by key_spec
exists in this key store.
Sourcefn get(
&self,
key_spec: &dyn KeySpecifier,
item_type: &KeystoreItemType,
) -> Result<Option<ErasedKey>>
fn get( &self, key_spec: &dyn KeySpecifier, item_type: &KeystoreItemType, ) -> Result<Option<ErasedKey>>
Retrieve the key identified by key_spec
.
Returns Ok(Some(key))
if the key was successfully retrieved. Returns Ok(None)
if the
key does not exist in this key store.
Sourcefn raw_entry_id(&self, raw_id: &str) -> Result<RawEntryId>
Available on crate feature onion-service-cli-extra
only.
fn raw_entry_id(&self, raw_id: &str) -> Result<RawEntryId>
onion-service-cli-extra
only.Convert the specified string to a RawEntryId
that
represents the raw unique identifier of an entry in this keystore.
The specified raw_id
is allowed to represent an unrecognized
or nonexistent entry.
Returns a RawEntryId
that is specific to this Keystore
implementation.
Returns an error if raw_id
cannot be converted to
the correct variant for this keystore implementation
(e.g.: RawEntryId::Path(PathBuf) for [
ArtiNativeKeystore`](crate::ArtiNativeKeystore)).
Important: a RawEntryId
should only be used to access
the entries of the keystore it originates from
(if used with a different keystore, the behavior is unspecified:
the operation may fail, it may succeed, or it may lead to the
wrong entry being accessed).
Sourcefn insert(
&self,
key: &dyn EncodableItem,
key_spec: &dyn KeySpecifier,
) -> Result<()>
fn insert( &self, key: &dyn EncodableItem, key_spec: &dyn KeySpecifier, ) -> Result<()>
Write key
to the key store.
Sourcefn remove(
&self,
key_spec: &dyn KeySpecifier,
item_type: &KeystoreItemType,
) -> Result<Option<()>>
fn remove( &self, key_spec: &dyn KeySpecifier, item_type: &KeystoreItemType, ) -> Result<Option<()>>
Remove the specified key.
A return value of Ok(None)
indicates the key doesn’t exist in this key store, whereas
Ok(Some(())
means the key was successfully removed.
Returns Err
if an error occurred while trying to remove the key.
Sourcefn remove_unchecked(&self, entry_id: &RawEntryId) -> Result<()>
Available on crate feature onion-service-cli-extra
only.
fn remove_unchecked(&self, entry_id: &RawEntryId) -> Result<()>
onion-service-cli-extra
only.Remove the specified keystore entry.
This method accepts both recognized and unrecognized entries, identified
by a RawEntryId
instance.
If the entry wasn’t successfully removed, or if the entry doesn’t
exists, Err
is returned.
Sourcefn list(&self) -> Result<Vec<KeystoreEntryResult<KeystoreEntry<'_>>>>
fn list(&self) -> Result<Vec<KeystoreEntryResult<KeystoreEntry<'_>>>>
List all the entries in this keystore.
Returns a list of results, where Ok
signifies a recognized entry,
and Err(KeystoreListError)
an unrecognized one.
An entry is said to be recognized if it has a valid KeyPath
.
Implementors§
impl Keystore for ArtiEphemeralKeystore
ephemeral-keystore
only.impl Keystore for ArtiNativeKeystore
impl Keystore for CTorClientKeystore
ctor-keystore
only.impl Keystore for CTorServiceKeystore
ctor-keystore
only.