identity_storage/storage/
mod.rs

1// Copyright 2020-2025 IOTA Stiftung, Fondazione LINKS
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 = "hybrid")]
10mod hybrid_jws_document_ext;
11#[cfg(feature = "jpt-bbs-plus")]
12mod jwp_document_ext;
13#[cfg(feature = "pqc")]
14mod pqc_jws_document_ext;
15mod signature_options;
16#[cfg(feature = "jpt-bbs-plus")]
17mod timeframe_revocation_ext;
18
19mod did_jwk_document_ext;
20
21#[cfg(feature = "storage-signer")]
22mod storage_signer;
23#[cfg(all(test, feature = "memstore"))]
24pub(crate) mod tests;
25
26pub use error::*;
27
28#[cfg(feature = "hybrid")]
29pub use hybrid_jws_document_ext::*;
30pub use jwk_document_ext::*;
31#[cfg(feature = "jpt-bbs-plus")]
32pub use jwp_document_ext::*;
33#[cfg(feature = "pqc")]
34pub use pqc_jws_document_ext::*;
35pub use signature_options::*;
36#[cfg(feature = "storage-signer")]
37pub use storage_signer::*;
38#[cfg(feature = "jpt-bbs-plus")]
39pub use timeframe_revocation_ext::*;
40
41pub use did_jwk_document_ext::*;
42
43/// A type wrapping a key and key id storage, typically used with [`JwkStorage`](crate::key_storage::JwkStorage) and
44/// [`KeyIdStorage`](crate::key_id_storage::KeyIdStorage) that should always be used together when calling methods from
45/// [`JwkDocumentExt`](crate::storage::JwkDocumentExt).
46pub struct Storage<K, I> {
47  key_storage: K,
48  key_id_storage: I,
49}
50
51impl<K, I> Storage<K, I> {
52  /// Constructs a new [`Storage`].
53  pub fn new(key_storage: K, key_id_storage: I) -> Self {
54    Self {
55      key_storage,
56      key_id_storage,
57    }
58  }
59
60  /// Obtain a reference to the wrapped [`JwkStorage`](crate::key_storage::JwkStorage).
61  pub fn key_storage(&self) -> &K {
62    &self.key_storage
63  }
64
65  /// Obtain a reference to the wrapped [`KeyIdStorage`](crate::key_id_storage::KeyIdStorage).
66  pub fn key_id_storage(&self) -> &I {
67    &self.key_id_storage
68  }
69}
70
71#[cfg(feature = "keytool")]
72mod keytool {
73  use super::Storage;
74  use iota_interaction::KeytoolStorage as Keytool;
75
76  /// An unsecure [Storage] that leverages IOTA Keytool.
77  pub type KeytoolStorage = Storage<Keytool, Keytool>;
78
79  impl From<Keytool> for KeytoolStorage {
80    fn from(keytool: Keytool) -> Self {
81      KeytoolStorage::new(keytool.clone(), keytool)
82    }
83  }
84}
85
86#[cfg(feature = "keytool")]
87pub use keytool::*;