1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
use crate::{
Contact, ContactsDb, KeyAttributes, ProfileChangeEvent, ProfileEventAttributes,
ProfileIdentifier, ProfileSync, TrustPolicy,
};
use async_trait::async_trait;
use ockam_core::{Address, Result, Route};
use ockam_node::Context;
use ockam_vault_core::{PublicKey, Secret};
pub trait ProfileIdentity {
fn identifier(&self) -> Result<ProfileIdentifier>;
}
pub trait ProfileChanges {
fn change_events(&self) -> Result<Vec<ProfileChangeEvent>>;
fn update_no_verification(&mut self, change_event: ProfileChangeEvent) -> Result<()>;
fn verify(&mut self) -> Result<bool>;
}
pub trait ProfileContacts {
fn contacts(&self) -> Result<ContactsDb>;
fn to_contact(&self) -> Result<Contact>;
fn serialize_to_contact(&self) -> Result<Vec<u8>>;
fn get_contact(&self, id: &ProfileIdentifier) -> Result<Option<Contact>>;
fn verify_contact(&mut self, contact: &Contact) -> Result<bool>;
fn verify_and_add_contact(&mut self, contact: Contact) -> Result<bool>;
fn verify_and_update_contact(
&mut self,
profile_id: &ProfileIdentifier,
change_events: Vec<ProfileChangeEvent>,
) -> Result<bool>;
}
pub trait ProfileAuth {
fn generate_authentication_proof(&mut self, channel_state: &[u8]) -> Result<Vec<u8>>;
fn verify_authentication_proof(
&mut self,
channel_state: &[u8],
responder_contact_id: &ProfileIdentifier,
proof: &[u8],
) -> Result<bool>;
}
pub trait ProfileSecrets {
fn create_key(
&mut self,
key_attributes: KeyAttributes,
attributes: Option<ProfileEventAttributes>,
) -> Result<()>;
fn rotate_key(
&mut self,
key_attributes: KeyAttributes,
attributes: Option<ProfileEventAttributes>,
) -> Result<()>;
fn get_secret_key(&mut self, key_attributes: &KeyAttributes) -> Result<Secret>;
fn get_public_key(&self, key_attributes: &KeyAttributes) -> Result<PublicKey>;
fn get_root_secret(&mut self) -> Result<Secret>;
}
#[async_trait]
pub trait SecureChannelTrait {
async fn create_secure_channel(
&mut self,
ctx: &Context,
route: Route,
trust_policy: impl TrustPolicy,
vault: &Address,
) -> Result<Address>;
async fn create_secure_channel_listener(
&mut self,
ctx: &Context,
address: Address,
trust_policy: impl TrustPolicy,
vault: &Address,
) -> Result<()>;
}
pub trait ProfileTrait:
ProfileIdentity + ProfileChanges + ProfileSecrets + ProfileContacts + ProfileAuth + Send + 'static
{
}
impl<P> ProfileTrait for P where
P: ProfileIdentity
+ ProfileChanges
+ ProfileSecrets
+ ProfileContacts
+ ProfileAuth
+ Send
+ 'static
{
}
pub trait ProfileRetrieve {
fn profile(&self, profile_identifier: &ProfileIdentifier) -> Option<&ProfileSync>;
fn profile_mut(&mut self, profile_identifier: &ProfileIdentifier) -> Option<&mut ProfileSync>;
}
pub trait ProfileAdd {
fn add_profile(&mut self, profile: ProfileSync) -> Result<()>;
}
pub trait ProfileRemove {
fn remove_profile(&mut self, profile_id: &ProfileIdentifier) -> Result<()>;
}
pub trait ProfileManagement: ProfileAdd + ProfileRemove {}