kanidmd_lib/credential/
apppwd.rs
1use crate::credential::{CryptoPolicy, Password};
2use crate::prelude::*;
3use kanidm_proto::internal::OperationError;
4use std::cmp::Ordering;
5use std::fmt;
6
7#[derive(Clone)]
8pub struct ApplicationPassword {
9 pub uuid: Uuid,
10 pub(crate) application: Uuid,
11 pub(crate) label: String,
12 pub(crate) password: Password,
13}
14
15impl fmt::Debug for ApplicationPassword {
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 f.debug_struct("ApplicationPassword")
18 .field("uuid", &self.uuid)
19 .field("application", &self.application)
20 .field("label", &self.label)
21 .finish()
22 }
23}
24
25impl ApplicationPassword {
26 pub fn new(
27 application: Uuid,
28 label: &str,
29 cleartext: &str,
30 policy: &CryptoPolicy,
31 ) -> Result<ApplicationPassword, OperationError> {
32 let pw = Password::new(policy, cleartext).map_err(|e| {
33 error!(crypto_err = ?e);
34 e.into()
35 })?;
36 let ap = ApplicationPassword {
37 uuid: Uuid::new_v4(),
38 application,
39 label: label.to_string(),
40 password: pw,
41 };
42 Ok(ap)
43 }
44}
45
46impl PartialEq for ApplicationPassword {
47 fn eq(&self, other: &Self) -> bool {
48 self.uuid == other.uuid
49 || (self.application == other.application && self.label == other.label)
50 }
51}
52
53impl Eq for ApplicationPassword {}
54
55impl PartialOrd for ApplicationPassword {
56 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
57 Some(self.cmp(other))
58 }
59}
60
61impl Ord for ApplicationPassword {
62 fn cmp(&self, other: &Self) -> Ordering {
63 self.uuid.cmp(&other.uuid)
64 }
65}