From e96091091a015c7ed64a8c5f27e91b4a23db059f Mon Sep 17 00:00:00 2001 From: Hinton Date: Mon, 6 May 2024 11:50:10 +0200 Subject: [PATCH] Resolve review feedback --- .../bitwarden-crypto/src/sensitive/string.rs | 30 ++++++++++--------- .../src/platform/fido2/authenticator.rs | 4 +-- crates/bitwarden/src/platform/fido2/client.rs | 8 ++--- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/crates/bitwarden-crypto/src/sensitive/string.rs b/crates/bitwarden-crypto/src/sensitive/string.rs index 9887765b8..cd2db18eb 100644 --- a/crates/bitwarden-crypto/src/sensitive/string.rs +++ b/crates/bitwarden-crypto/src/sensitive/string.rs @@ -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); @@ -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] diff --git a/crates/bitwarden/src/platform/fido2/authenticator.rs b/crates/bitwarden/src/platform/fido2/authenticator.rs index 9f35a682d..311f014b2 100644 --- a/crates/bitwarden/src/platform/fido2/authenticator.rs +++ b/crates/bitwarden/src/platform/fido2/authenticator.rs @@ -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())), r#type: crate::vault::CipherType::Login, login: Some(LoginView { username: None, diff --git a/crates/bitwarden/src/platform/fido2/client.rs b/crates/bitwarden/src/platform/fido2/client.rs index a175e17bb..d53800958 100644 --- a/crates/bitwarden/src/platform/fido2/client.rs +++ b/crates/bitwarden/src/platform/fido2/client.rs @@ -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())), r#type: crate::vault::CipherType::Login, login: Some(LoginView { username: None, @@ -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())), r#type: crate::vault::CipherType::Login, login: Some(LoginView { username: None,