Skip to content

Commit

Permalink
Impl FromStr for SecretString
Browse files Browse the repository at this point in the history
  • Loading branch information
Eyob94 committed Sep 11, 2024
1 parent b35284c commit a6c3a8b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.1.5 - 2024-09-11
- [#10](https://github.com/Eyob94/shush-rs/pull/9) FromStr
- Implement `FromStr` trait for SecretString
- Add public alias `SecretString` and `SecretVec`

## 0.1.4 - 2024-09-11

- [#9](https://github.com/Eyob94/shush-rs/pull/9) Mutable Reference
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shush-rs"
version = "0.1.4"
version = "0.1.5"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "A Rust crate designed to manage sensitive data securely by leveraging memory protection mechanisms."
Expand Down
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use core::{
any,
fmt::{self, Debug},
};
use std::mem::size_of_val;
use std::ops::{Deref, DerefMut};
use std::{mem::size_of_val, str::FromStr};

#[cfg(unix)]
use errno::errno;
Expand Down Expand Up @@ -37,6 +37,16 @@ impl<S: Zeroize> Zeroize for SecretBox<S> {
}
}

/// Convenient type alias for Secret Wrapped Strings
pub type SecretString = SecretBox<String>;

impl FromStr for SecretString {
type Err = core::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(SecretBox::new(Box::new(s.to_string())))
}
}

impl<S: Zeroize> Drop for SecretBox<S> {
fn drop(&mut self) {
let len = size_of_val(&*self.inner_secret);
Expand Down

0 comments on commit a6c3a8b

Please sign in to comment.