Skip to content

Commit

Permalink
Cleanup + PR feedback + rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Jun 7, 2024
1 parent 4731901 commit ee7d6db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 8 additions & 8 deletions aws-lc-rs/src/cipher/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl StreamingEncryptingKey {
context: EncryptionContext,
) -> Result<Self, Unspecified> {
let algorithm = key.algorithm();
let cipher_ctx = LcPtr::new(unsafe { EVP_CIPHER_CTX_new() })?;
let mut cipher_ctx = LcPtr::new(unsafe { EVP_CIPHER_CTX_new() })?;
let cipher = mode.evp_cipher(key.algorithm);
let key_bytes = key.key_bytes.as_ref();
debug_assert_eq!(
Expand Down Expand Up @@ -100,11 +100,11 @@ impl StreamingEncryptingKey {
/// potentially writing bytes of ciphertext to `output`.
///
/// The number of bytes written to `output` can be up to `input.len()`
/// plus the block length of the algorithm (e.g., 16 bytes for AES).
/// plus the block length of the algorithm (e.g., [`Algorithm::block_len`]).
///
/// # Errors
/// * May return an error if the `output` buffer is smaller than the length of
/// the `input` plus the algorithm's block length. Certain cipher modes
/// the `input` plus the algorithm's block length (e.g. [`Algorithm::block_len`]). Certain cipher modes
/// (such as CTR) may allow the output buffer to be as small as the size
/// of the input in certain circumstances.
/// * Returns an error if the length of either `input` or `output` is larger
Expand Down Expand Up @@ -135,15 +135,15 @@ impl StreamingEncryptingKey {
/// `output`.
///
/// The number of bytes written to `output` can be up to the block length of
/// the algorithm (e.g., 16 bytes for AES).
/// [`Algorithm::block_len`].
///
/// # Errors
/// * May return an error if the `output` buffer is smaller than the algorithm's
/// block length. Certain cipher mode (such as CTR) may allow the output
/// buffer to only be large enough to fit the remainder of the ciphertext.
/// * Returns an error if the length of `output` is larger than `i32::MAX`.
pub fn finish(
self,
mut self,
output: &mut [u8],
) -> Result<(DecryptionContext, BufferUpdate), Unspecified> {
let mut outlen: i32 = output.len().try_into()?;
Expand Down Expand Up @@ -240,7 +240,7 @@ impl StreamingDecryptingKey {
mode: OperatingMode,
context: DecryptionContext,
) -> Result<Self, Unspecified> {
let cipher_ctx = LcPtr::new(unsafe { EVP_CIPHER_CTX_new() })?;
let mut cipher_ctx = LcPtr::new(unsafe { EVP_CIPHER_CTX_new() })?;
let algorithm = key.algorithm();
let cipher = mode.evp_cipher(key.algorithm);
let key_bytes = key.key_bytes.as_ref();
Expand Down Expand Up @@ -276,7 +276,7 @@ impl StreamingDecryptingKey {
/// Updates the internal state of the key with the provided ciphertext `input`,
/// potentially also writing bytes of plaintext to `output`.
/// The number of bytes written to `output` can be up to `input.len()`
/// plus the block length of the cipher algorithm (e.g., 16 bytes for AES).
/// plus the block length of the cipher algorithm (e.g., [`Algorithm::block_len`]).
///
/// # Errors
/// * May return an error if the `output` buffer is smaller than the length of
Expand Down Expand Up @@ -310,7 +310,7 @@ impl StreamingDecryptingKey {
/// Finishes the decryption operation, writing the remaining plaintext to
/// `output`.
/// The number of bytes written to `output` can be up to the block length of
/// the cipher algorithm (e.g., 16 bytes for AES).
/// the cipher algorithm (e.g., [`Algorithm::block_len`]).
///
/// # Errors
/// * May return an error if the `output` buffer is smaller than the algorithm's
Expand Down
8 changes: 8 additions & 0 deletions aws-lc-rs/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 OR ISC

use core::ops::Deref;
use std::ops::DerefMut;

use aws_lc::{
BN_free, ECDSA_SIG_free, EC_GROUP_free, EC_KEY_free, EC_POINT_free, EVP_AEAD_CTX_free,
Expand All @@ -28,6 +29,13 @@ impl<P: Pointer> Deref for ManagedPointer<P> {
}
}

impl<P: Pointer> DerefMut for ManagedPointer<P> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.pointer
}
}

impl<P: Pointer> ManagedPointer<P> {
#[inline]
pub fn new<T: IntoPointer<P>>(value: T) -> Result<Self, ()> {
Expand Down

0 comments on commit ee7d6db

Please sign in to comment.