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
use auth_key::AuthKey;
use object::ObjectId;
pub const DEFAULT_AUTH_KEY_ID: ObjectId = 1;
pub struct Credentials {
pub auth_key_id: ObjectId,
pub auth_key: AuthKey,
}
impl Credentials {
pub fn new(auth_key_id: ObjectId, auth_key: AuthKey) -> Self {
Self {
auth_key_id,
auth_key,
}
}
#[cfg(feature = "passwords")]
pub fn from_password(auth_key_id: ObjectId, password: &[u8]) -> Self {
Self::new(auth_key_id, AuthKey::derive_from_password(password))
}
}
#[cfg(feature = "passwords")]
impl Default for Credentials {
fn default() -> Self {
Self::new(DEFAULT_AUTH_KEY_ID, AuthKey::default())
}
}