identity_storage/storage/
mod.rs

1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! This module provides a type wrapping a key and key id storage.
5
6mod error;
7#[macro_use]
8mod jwk_document_ext;
9#[cfg(feature = "jpt-bbs-plus")]
10mod jwp_document_ext;
11mod signature_options;
12#[cfg(feature = "jpt-bbs-plus")]
13mod timeframe_revocation_ext;
14
15#[cfg(feature = "storage-signer")]
16mod storage_signer;
17#[cfg(all(test, feature = "memstore"))]
18pub(crate) mod tests;
19
20pub use error::*;
21
22pub use jwk_document_ext::*;
23#[cfg(feature = "jpt-bbs-plus")]
24pub use jwp_document_ext::*;
25pub use signature_options::*;
26#[cfg(feature = "storage-signer")]
27pub use storage_signer::*;
28#[cfg(feature = "jpt-bbs-plus")]
29pub use timeframe_revocation_ext::*;
30
31/// A type wrapping a key and key id storage, typically used with [`JwkStorage`](crate::key_storage::JwkStorage) and
32/// [`KeyIdStorage`](crate::key_id_storage::KeyIdStorage) that should always be used together when calling methods from
33/// [`JwkDocumentExt`](crate::storage::JwkDocumentExt).
34pub struct Storage<K, I> {
35  key_storage: K,
36  key_id_storage: I,
37}
38
39impl<K, I> Storage<K, I> {
40  /// Constructs a new [`Storage`].
41  pub fn new(key_storage: K, key_id_storage: I) -> Self {
42    Self {
43      key_storage,
44      key_id_storage,
45    }
46  }
47
48  /// Obtain a reference to the wrapped [`JwkStorage`](crate::key_storage::JwkStorage).
49  pub fn key_storage(&self) -> &K {
50    &self.key_storage
51  }
52
53  /// Obtain a reference to the wrapped [`KeyIdStorage`](crate::key_id_storage::KeyIdStorage).
54  pub fn key_id_storage(&self) -> &I {
55    &self.key_id_storage
56  }
57}
58
59#[cfg(feature = "keytool")]
60mod keytool {
61  use super::Storage;
62  use iota_interaction::KeytoolStorage as Keytool;
63
64  /// An unsecure [Storage] that leverages IOTA Keytool.
65  pub type KeytoolStorage = Storage<Keytool, Keytool>;
66
67  impl From<Keytool> for KeytoolStorage {
68    fn from(keytool: Keytool) -> Self {
69      KeytoolStorage::new(keytool.clone(), keytool)
70    }
71  }
72}
73
74#[cfg(feature = "keytool")]
75pub use keytool::*;