identity_storage/key_id_storage/
key_id_storage.rs

1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::key_storage::KeyId;
5use async_trait::async_trait;
6
7use super::key_id_storage_error::KeyIdStorageError;
8use super::method_digest::MethodDigest;
9
10/// Result of key id storage operations.
11pub type KeyIdStorageResult<T> = Result<T, KeyIdStorageError>;
12
13/// Key value Storage for [`KeyId`] under [`MethodDigest`].
14#[cfg_attr(not(feature = "send-sync-storage"), async_trait(?Send))]
15#[cfg_attr(feature = "send-sync-storage", async_trait)]
16pub trait KeyIdStorage: storage_sub_trait::StorageSendSyncMaybe {
17  /// Insert a [`KeyId`] into the [`KeyIdStorage`] under the given [`MethodDigest`].
18  ///
19  /// If an entry for `key` already exists in the storage an error must be returned
20  /// immediately without altering the state of the storage.
21  async fn insert_key_id(&self, method_digest: MethodDigest, key_id: KeyId) -> KeyIdStorageResult<()>;
22
23  /// Obtain the [`KeyId`] associated with the given [`MethodDigest`].
24  async fn get_key_id(&self, method_digest: &MethodDigest) -> KeyIdStorageResult<KeyId>;
25
26  /// Delete the [`KeyId`] associated with the given [`MethodDigest`] from the [`KeyIdStorage`].
27  ///
28  /// If `key` is not found in storage, an Error must be returned.
29  async fn delete_key_id(&self, method_digest: &MethodDigest) -> KeyIdStorageResult<()>;
30}
31
32#[cfg(not(feature = "send-sync-storage"))]
33mod storage_sub_trait {
34  pub trait StorageSendSyncMaybe {}
35  impl<S: super::KeyIdStorage> StorageSendSyncMaybe for S {}
36}
37
38#[cfg(feature = "send-sync-storage")]
39mod storage_sub_trait {
40  pub trait StorageSendSyncMaybe: Send + Sync {}
41  impl<S: Send + Sync + super::KeyIdStorage> StorageSendSyncMaybe for S {}
42}