1use mz_ore::secure::Zeroize;
11use proptest_derive::Arbitrary;
12use serde::{Deserialize, Serialize};
13use std::fmt::{Debug, Display};
14
15use static_assertions::assert_not_impl_all;
16
17#[derive(
19 Clone,
20 PartialEq,
21 Eq,
22 Serialize,
23 Deserialize,
24 PartialOrd,
25 Ord,
26 Arbitrary
27)]
28pub struct Password(pub String);
29
30assert_not_impl_all!(Password: Display);
31
32impl From<String> for Password {
33 fn from(password: String) -> Self {
34 Password(password)
35 }
36}
37
38impl From<&str> for Password {
39 fn from(password: &str) -> Self {
40 Password(password.to_string())
41 }
42}
43
44impl Password {
45 pub fn as_bytes(&self) -> &[u8] {
50 self.0.as_bytes()
51 }
52
53 pub fn as_str(&self) -> &str {
55 &self.0
56 }
57}
58
59impl Drop for Password {
60 fn drop(&mut self) {
61 self.0.zeroize();
62 }
63}
64
65impl Debug for Password {
66 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
67 write!(f, "Password(****)")
68 }
69}