v0.2.5-pre.002
This commit is contained in:
74
crates/ksp-wallet-lib/src/password.rs
Normal file
74
crates/ksp-wallet-lib/src/password.rs
Normal file
@@ -0,0 +1,74 @@
|
||||
// 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;
|
||||
Reference in New Issue
Block a user