Skip to content

Commit

Permalink
Add some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed May 3, 2024
1 parent e78c2bc commit aaff51d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/bitwarden-crypto/src/sensitive/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl SensitiveString {
}
}

/// Creates a new empty `SensitiveString` with at least the specified capacity.
pub fn with_capacity(len: usize) -> Self {
Self {
inner: Zeroizing::new(String::with_capacity(len)),
Expand Down Expand Up @@ -73,10 +74,16 @@ impl SensitiveString {
self.inner.push_str(s);
}

/// Expose the inner value as a str slice.
///
/// Warning: Taking ownership of the inner value will create a copy of the string.
pub fn as_str(&self) -> &str {
&self.inner
}

/// Expose the inner value as a byte slice.
///
/// Warning: Taking ownership of the inner value will create a copy of the string.
pub fn as_bytes(&self) -> &[u8] {
self.inner.as_bytes()
}
Expand Down Expand Up @@ -106,6 +113,8 @@ impl SensitiveString {
}

impl Default for SensitiveString {
/// Creates an empty `SensitiveString`.
#[inline]
fn default() -> Self {
Self::new(String::default())
}

Check warning on line 120 in crates/bitwarden-crypto/src/sensitive/string.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-crypto/src/sensitive/string.rs#L118-L120

Added lines #L118 - L120 were not covered by tests
Expand Down

0 comments on commit aaff51d

Please sign in to comment.