Skip to content

Commit

Permalink
Merge pull request #1 from 448-engineering/better_api
Browse files Browse the repository at this point in the history
Better api
  • Loading branch information
448-OG authored May 22, 2023
2 parents 49503cb + b418d65 commit 3c663e7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "memsecurity"
version = "1.0.0"
version = "1.2.0"
authors = ["448 ENGINEERING DESIGN DEVELOPERS <superuser@448.africa>"]
license = "Apache-2.0 OR MIT"
description = "Securely hold secrets in memory and protect them against cross-protection-boundary readout via microarchitectural, via attacks on physical layout, and via coldboot attacks."
Expand Down
5 changes: 3 additions & 2 deletions src/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ mod keymaker {
Err(_) => return Err(MemSecurityErr::EncryptionErr)
}

let ciphertext = ZeroizeBytesArray::with_additional_capacity(TAG_LENGTH).set(buffer);
let ciphertext =
ZeroizeBytesArray::with_additional_capacity(TAG_LENGTH).set_bytes_mut(buffer);

self.add_ciphertext(ciphertext);

Expand All @@ -112,7 +113,7 @@ mod keymaker {
b"",
&mut buffer,
) {
Ok(_) => Ok(ZeroizeBytesArray::new().set(buffer)),
Ok(_) => Ok(ZeroizeBytesArray::new().set_bytes_mut(buffer)),
Err(_) => {
buffer.fill(0); // Zero out the partially decrypted plaintext
drop(buffer); // Drop the partially leaked plaintext
Expand Down
33 changes: 32 additions & 1 deletion src/zeroizable_arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,24 @@ impl<const N: usize> ZeroizeBytesArray<N> {
ZeroizeBytesArray(BytesMut::with_capacity(N))
}

/// Initialize the array and set the internal value of the array to the value specified by method argument
pub fn new_with_data(value: [u8; N]) -> Self {
let mut value_bytes = BytesMut::with_capacity(N);

value_bytes.put(&value[..]);

ZeroizeBytesArray(value_bytes)
}

/// Set the internal value of the array to the value specified by method argument
pub fn set(mut self, value: BytesMut) -> Self {
pub fn set(mut self, value: [u8; N]) -> Self {
self.0.put(&value[..]);

self
}

/// Set the internal value of the array to the value specified by method argument value which is a `BytesMut`
pub fn set_bytes_mut(mut self, value: BytesMut) -> Self {
self.0.put(&value[..]);

self
Expand Down Expand Up @@ -197,6 +213,21 @@ impl ZeroizeBytes {
ZeroizeBytes(BytesMut::new())
}

/// Initialize the array and set the internal value of the array to the value specified by method argument
pub fn new_with_data(value: &[u8]) -> Self {
let mut value_bytes = BytesMut::new();
value_bytes.put(&value[..]);

ZeroizeBytes(value_bytes)
}

/// Set the internal value of the array to the value specified by method argument value which is a `BytesMut`
pub fn set_bytes_mut(mut self, value: BytesMut) -> Self {
self.0.put(&value[..]);

self
}

/// Sets the internal value to the new value
pub fn set(&mut self, value: BytesMut) -> &mut Self {
self.0.put(&value[..]);
Expand Down

0 comments on commit 3c663e7

Please sign in to comment.