Skip to content

Commit ee7d6db

Browse files
committed
Cleanup + PR feedback + rebase
1 parent 4731901 commit ee7d6db

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

aws-lc-rs/src/cipher/streaming.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl StreamingEncryptingKey {
6363
context: EncryptionContext,
6464
) -> Result<Self, Unspecified> {
6565
let algorithm = key.algorithm();
66-
let cipher_ctx = LcPtr::new(unsafe { EVP_CIPHER_CTX_new() })?;
66+
let mut cipher_ctx = LcPtr::new(unsafe { EVP_CIPHER_CTX_new() })?;
6767
let cipher = mode.evp_cipher(key.algorithm);
6868
let key_bytes = key.key_bytes.as_ref();
6969
debug_assert_eq!(
@@ -100,11 +100,11 @@ impl StreamingEncryptingKey {
100100
/// potentially writing bytes of ciphertext to `output`.
101101
///
102102
/// The number of bytes written to `output` can be up to `input.len()`
103-
/// plus the block length of the algorithm (e.g., 16 bytes for AES).
103+
/// plus the block length of the algorithm (e.g., [`Algorithm::block_len`]).
104104
///
105105
/// # Errors
106106
/// * May return an error if the `output` buffer is smaller than the length of
107-
/// the `input` plus the algorithm's block length. Certain cipher modes
107+
/// the `input` plus the algorithm's block length (e.g. [`Algorithm::block_len`]). Certain cipher modes
108108
/// (such as CTR) may allow the output buffer to be as small as the size
109109
/// of the input in certain circumstances.
110110
/// * Returns an error if the length of either `input` or `output` is larger
@@ -135,15 +135,15 @@ impl StreamingEncryptingKey {
135135
/// `output`.
136136
///
137137
/// The number of bytes written to `output` can be up to the block length of
138-
/// the algorithm (e.g., 16 bytes for AES).
138+
/// [`Algorithm::block_len`].
139139
///
140140
/// # Errors
141141
/// * May return an error if the `output` buffer is smaller than the algorithm's
142142
/// block length. Certain cipher mode (such as CTR) may allow the output
143143
/// buffer to only be large enough to fit the remainder of the ciphertext.
144144
/// * Returns an error if the length of `output` is larger than `i32::MAX`.
145145
pub fn finish(
146-
self,
146+
mut self,
147147
output: &mut [u8],
148148
) -> Result<(DecryptionContext, BufferUpdate), Unspecified> {
149149
let mut outlen: i32 = output.len().try_into()?;
@@ -240,7 +240,7 @@ impl StreamingDecryptingKey {
240240
mode: OperatingMode,
241241
context: DecryptionContext,
242242
) -> Result<Self, Unspecified> {
243-
let cipher_ctx = LcPtr::new(unsafe { EVP_CIPHER_CTX_new() })?;
243+
let mut cipher_ctx = LcPtr::new(unsafe { EVP_CIPHER_CTX_new() })?;
244244
let algorithm = key.algorithm();
245245
let cipher = mode.evp_cipher(key.algorithm);
246246
let key_bytes = key.key_bytes.as_ref();
@@ -276,7 +276,7 @@ impl StreamingDecryptingKey {
276276
/// Updates the internal state of the key with the provided ciphertext `input`,
277277
/// potentially also writing bytes of plaintext to `output`.
278278
/// The number of bytes written to `output` can be up to `input.len()`
279-
/// plus the block length of the cipher algorithm (e.g., 16 bytes for AES).
279+
/// plus the block length of the cipher algorithm (e.g., [`Algorithm::block_len`]).
280280
///
281281
/// # Errors
282282
/// * May return an error if the `output` buffer is smaller than the length of
@@ -310,7 +310,7 @@ impl StreamingDecryptingKey {
310310
/// Finishes the decryption operation, writing the remaining plaintext to
311311
/// `output`.
312312
/// The number of bytes written to `output` can be up to the block length of
313-
/// the cipher algorithm (e.g., 16 bytes for AES).
313+
/// the cipher algorithm (e.g., [`Algorithm::block_len`]).
314314
///
315315
/// # Errors
316316
/// * May return an error if the `output` buffer is smaller than the algorithm's

aws-lc-rs/src/ptr.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0 OR ISC
33

44
use core::ops::Deref;
5+
use std::ops::DerefMut;
56

67
use aws_lc::{
78
BN_free, ECDSA_SIG_free, EC_GROUP_free, EC_KEY_free, EC_POINT_free, EVP_AEAD_CTX_free,
@@ -28,6 +29,13 @@ impl<P: Pointer> Deref for ManagedPointer<P> {
2829
}
2930
}
3031

32+
impl<P: Pointer> DerefMut for ManagedPointer<P> {
33+
#[inline]
34+
fn deref_mut(&mut self) -> &mut Self::Target {
35+
&mut self.pointer
36+
}
37+
}
38+
3139
impl<P: Pointer> ManagedPointer<P> {
3240
#[inline]
3341
pub fn new<T: IntoPointer<P>>(value: T) -> Result<Self, ()> {

0 commit comments

Comments
 (0)