Skip to content

Commit

Permalink
Resolve review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed May 6, 2024
1 parent 456be09 commit e960910
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
30 changes: 16 additions & 14 deletions crates/bitwarden-crypto/src/sensitive/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,36 @@ impl SensitiveString {

/// Extend the size of the string by `size`.
///
/// Internally creates a new string with the new size and copies the old string into it.
pub fn extend_size(&mut self, size: usize) {
let mut new_inner = Zeroizing::new(String::with_capacity(size));
/// Internally creates a new string with the new size and copies the old string into it,
/// zeroing the original.
fn extend_size(&mut self, size: usize) {
let new_size = self.inner.len() + size;
let mut new_inner = Zeroizing::new(String::with_capacity(new_size));
new_inner.push_str(&self.inner);

self.inner = new_inner;
}

/// Extends the capacity of the string to `size` if it is larger than the current capacity.
pub fn extend_spec(&mut self, size: usize) {
fn extend_spec(&mut self, size: usize) {
if size > self.inner.capacity() {
self.extend_size(size);
}
}

/// Appends a given char onto the end of this `BitString`
/// Appends a given char onto the end of this `SensitiveString`
///
/// If the capacity of the `BitString` is not large enough it will zeroize the current string
/// and create a new string with the new size.
/// If the capacity of the `SensitiveString` is not large enough it will zeroize the current
/// string and create a new string with the new size.
pub fn push(&mut self, c: char) {
self.extend_spec(self.inner.len() + c.len_utf8());
self.inner.push(c);
}

/// Appends a given string slice onto the end of this `BitString`
/// Appends a given string slice onto the end of this `SensitiveString`
///
/// If the capacity of the `BitString` is not large enough it will zeroize the current string
/// and create a new string with the new size.
/// If the capacity of the `SensitiveString` is not large enough it will zeroize the current
/// string and create a new string with the new size.
pub fn push_str(&mut self, s: &str) {
self.extend_spec(self.inner.len() + s.len());
self.inner.push_str(s);
Expand Down Expand Up @@ -202,11 +204,11 @@ mod tests {
use super::*;

#[test]
fn test_bit_string() {
let mut bit_string = SensitiveString::new("hello".to_string());
bit_string.push_str(" world");
fn test_senitive_string() {
let mut s = SensitiveString::new("hello".to_string());
s.push_str(" world");

assert_eq!(bit_string.inner.as_str(), "hello world");
assert_eq!(s.inner.as_str(), "hello world");
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden/src/platform/fido2/authenticator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ impl<'a> Fido2Authenticator<'a> {
folder_id: None,
collection_ids: vec![],
key: None,
name: SensitiveString::new(Box::new("".to_string())),
notes: Some(SensitiveString::new(Box::new("".to_string()))),
name: SensitiveString::new("".to_string()),
notes: Some(SensitiveString::new("".to_string())),

Check warning on line 129 in crates/bitwarden/src/platform/fido2/authenticator.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/authenticator.rs#L128-L129

Added lines #L128 - L129 were not covered by tests
r#type: crate::vault::CipherType::Login,
login: Some(LoginView {
username: None,
Expand Down
8 changes: 4 additions & 4 deletions crates/bitwarden/src/platform/fido2/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ impl<'a> Fido2Client<'a> {
folder_id: None,
collection_ids: vec![],
key: None,
name: SensitiveString::new(Box::new("".to_string())),
notes: Some(SensitiveString::new(Box::new("".to_string()))),
name: SensitiveString::new("".to_string()),
notes: Some(SensitiveString::new("".to_string())),

Check warning on line 88 in crates/bitwarden/src/platform/fido2/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/client.rs#L87-L88

Added lines #L87 - L88 were not covered by tests
r#type: crate::vault::CipherType::Login,
login: Some(LoginView {
username: None,
Expand Down Expand Up @@ -192,8 +192,8 @@ impl<'a> Fido2Client<'a> {
folder_id: None,
collection_ids: vec![],
key: None,
name: SensitiveString::new(Box::new("".to_string())),
notes: Some(SensitiveString::new(Box::new("".to_string()))),
name: SensitiveString::new("".to_string()),
notes: Some(SensitiveString::new("".to_string())),

Check warning on line 196 in crates/bitwarden/src/platform/fido2/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/platform/fido2/client.rs#L195-L196

Added lines #L195 - L196 were not covered by tests
r#type: crate::vault::CipherType::Login,
login: Some(LoginView {
username: None,
Expand Down

0 comments on commit e960910

Please sign in to comment.