-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace outdated secrecy library with own impl
- Loading branch information
Showing
10 changed files
with
49 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::sync::Arc; | ||
|
||
/// A cheaply clonable, zeroed on drop, String. | ||
/// | ||
/// This is a simple newtype of `Arc<str>` that uses [`zeroize::Zeroize`] on on last drop to avoid | ||
/// keeping it around in memory. | ||
#[derive(Clone, serde::Deserialize, serde::Serialize)] | ||
pub struct SecretString(Arc<str>); | ||
|
||
impl SecretString { | ||
#[must_use] | ||
pub fn new(inner: Arc<str>) -> Self { | ||
Self(inner) | ||
} | ||
|
||
#[must_use] | ||
pub fn expose_secret(&self) -> &str { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl std::fmt::Debug for SecretString { | ||
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
fmt.debug_tuple(std::any::type_name::<Self>()).field(&"<secret>").finish() | ||
} | ||
} | ||
|
||
impl zeroize::Zeroize for SecretString { | ||
fn zeroize(&mut self) { | ||
if let Some(string) = Arc::get_mut(&mut self.0) { | ||
string.zeroize(); | ||
} | ||
} | ||
} |