ockam_identity/secure_channels/
secure_channels_builder.rs1use ockam_core::compat::sync::Arc;
2#[cfg(feature = "storage")]
3use ockam_core::Result;
4use ockam_vault::storage::SecretsRepository;
5
6use crate::identities::ChangeHistoryRepository;
7use crate::purpose_keys::storage::PurposeKeysRepository;
8use crate::secure_channel::SecureChannelRegistry;
9use crate::secure_channels::SecureChannels;
10use crate::{
11 CredentialRepository, IdentitiesBuilder, IdentityAttributesRepository, SecureChannelRepository,
12 Vault,
13};
14
15#[derive(Clone)]
17pub struct SecureChannelsBuilder {
18 pub(crate) identities_builder: IdentitiesBuilder,
20 pub(crate) registry: SecureChannelRegistry,
21 pub(crate) secure_channel_repository: Arc<dyn SecureChannelRepository>,
22}
23
24#[cfg(feature = "storage")]
26pub async fn secure_channels() -> Result<Arc<SecureChannels>> {
27 Ok(SecureChannels::builder().await?.build())
28}
29
30impl SecureChannelsBuilder {
31 pub fn with_secrets_repository(mut self, repository: Arc<dyn SecretsRepository>) -> Self {
33 self.identities_builder = self.identities_builder.with_secrets_repository(repository);
34 self
35 }
36
37 pub fn with_vault(mut self, vault: Vault) -> Self {
39 self.identities_builder = self.identities_builder.with_vault(vault);
40 self
41 }
42
43 pub fn with_change_history_repository(
45 mut self,
46 repository: Arc<dyn ChangeHistoryRepository>,
47 ) -> Self {
48 self.identities_builder = self
49 .identities_builder
50 .with_change_history_repository(repository);
51 self
52 }
53
54 pub fn with_identity_attributes_repository(
56 mut self,
57 repository: Arc<dyn IdentityAttributesRepository>,
58 ) -> Self {
59 self.identities_builder = self
60 .identities_builder
61 .with_identity_attributes_repository(repository);
62 self
63 }
64
65 pub fn with_purpose_keys_repository(
67 mut self,
68 repository: Arc<dyn PurposeKeysRepository>,
69 ) -> Self {
70 self.identities_builder = self
71 .identities_builder
72 .with_purpose_keys_repository(repository);
73 self
74 }
75
76 pub fn with_cached_credential_repository(
78 mut self,
79 repository: Arc<dyn CredentialRepository>,
80 ) -> Self {
81 self.identities_builder = self
82 .identities_builder
83 .with_cached_credential_repository(repository);
84 self
85 }
86
87 pub fn with_secure_channel_repository(
89 mut self,
90 repository: Arc<dyn SecureChannelRepository>,
91 ) -> Self {
92 self.secure_channel_repository = repository;
93 self
94 }
95
96 pub fn with_secure_channels_registry(mut self, registry: SecureChannelRegistry) -> Self {
98 self.registry = registry;
99 self
100 }
101
102 pub fn build(self) -> Arc<SecureChannels> {
105 let identities = self.identities_builder.build();
106 Arc::new(SecureChannels::new(
107 identities,
108 self.registry,
109 self.secure_channel_repository,
110 ))
111 }
112}