Skip to main content

mz_auth/
password.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10use proptest_derive::Arbitrary;
11use serde::{Deserialize, Serialize};
12use std::fmt::{Debug, Display};
13
14use static_assertions::assert_not_impl_all;
15
16///Password is a String wrapper type that does not implement Display or Debug
17#[derive(
18    Clone,
19    PartialEq,
20    Eq,
21    Serialize,
22    Deserialize,
23    PartialOrd,
24    Ord,
25    Arbitrary
26)]
27pub struct Password(pub String);
28
29assert_not_impl_all!(Password: Display);
30
31impl From<String> for Password {
32    fn from(password: String) -> Self {
33        Password(password)
34    }
35}
36
37impl From<&str> for Password {
38    fn from(password: &str) -> Self {
39        Password(password.to_string())
40    }
41}
42
43impl ToString for Password {
44    fn to_string(&self) -> String {
45        self.0.clone()
46    }
47}
48
49impl Debug for Password {
50    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51        write!(f, "Password(****)")
52    }
53}