75 lines
2.1 KiB
Rust
75 lines
2.1 KiB
Rust
// file: crates/ksp-wallet-lib/src/password.rs
|
|
// version: 1
|
|
|
|
/// Owned VIEW password material.
|
|
///
|
|
/// The value is never exposed through `Debug` or `Display`, is intentionally non-`Clone`, and is zeroized on drop. Consumers should move an existing
|
|
/// `String` into this type instead of keeping unnecessary clear-text copies.
|
|
///
|
|
/// ```compile_fail
|
|
/// let password = ksp_wallet_lib::ViewPassword::new(std::string::String::from("test-only"));
|
|
/// let duplicated = password.clone();
|
|
/// let _ = duplicated;
|
|
/// ```
|
|
pub struct ViewPassword {
|
|
value: std::string::String,
|
|
}
|
|
|
|
impl ViewPassword {
|
|
/// Takes ownership of VIEW password material.
|
|
#[must_use]
|
|
pub fn new(value: std::string::String) -> Self {
|
|
return Self { value };
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Debug for ViewPassword {
|
|
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
return formatter.write_str("ViewPassword(<redacted>)");
|
|
}
|
|
}
|
|
|
|
impl std::ops::Drop for ViewPassword {
|
|
fn drop(&mut self) {
|
|
zeroize::Zeroize::zeroize(&mut self.value);
|
|
}
|
|
}
|
|
|
|
/// Owned OWNER password material.
|
|
///
|
|
/// The value is never exposed through `Debug` or `Display`, is intentionally non-`Clone`, and is zeroized on drop. Consumers should move an existing
|
|
/// `String` into this type instead of keeping unnecessary clear-text copies.
|
|
///
|
|
/// ```compile_fail
|
|
/// let password = ksp_wallet_lib::OwnerPassword::new(std::string::String::from("test-only"));
|
|
/// let duplicated = password.clone();
|
|
/// let _ = duplicated;
|
|
/// ```
|
|
pub struct OwnerPassword {
|
|
value: std::string::String,
|
|
}
|
|
|
|
impl OwnerPassword {
|
|
/// Takes ownership of OWNER password material.
|
|
#[must_use]
|
|
pub fn new(value: std::string::String) -> Self {
|
|
return Self { value };
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Debug for OwnerPassword {
|
|
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
return formatter.write_str("OwnerPassword(<redacted>)");
|
|
}
|
|
}
|
|
|
|
impl std::ops::Drop for OwnerPassword {
|
|
fn drop(&mut self) {
|
|
zeroize::Zeroize::zeroize(&mut self.value);
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "../unit_tests/password.rs"]
|
|
mod tests;
|