Skip to content

Commit

Permalink
fix: Fix Encryptor::encrypt and Decryptor::decrypt
Browse files Browse the repository at this point in the history
Change to take the buffer to write to as a mutable reference.
  • Loading branch information
sorairolake committed Oct 15, 2024
1 parent 2633732 commit 771daa9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions crates/scryptenc/CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ All notable changes to this project will be documented in this file.
The format is based on https://keepachangelog.com/[Keep a Changelog], and this
project adheres to https://semver.org/[Semantic Versioning].

== {compare-url}/scryptenc-v0.9.8\...HEAD[Unreleased]

=== Fixed

* Change `Encryptor::encrypt` and `Decryptor::decrypt` to take the buffer to
write to as a mutable reference ({pull-request-url}/457[#457])

== {compare-url}/scryptenc-v0.9.7\...scryptenc-v0.9.8[0.9.8] - 2024-07-31

=== Added
Expand Down
2 changes: 1 addition & 1 deletion crates/scryptenc/src/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'c> Decryptor<'c> {
/// cipher.decrypt(&mut buf).unwrap();
/// # assert_eq!(buf, data.as_slice());
/// ```
pub fn decrypt(&self, mut buf: impl AsMut<[u8]>) -> Result<()> {
pub fn decrypt(&self, buf: &mut (impl AsMut<[u8]> + ?Sized)) -> Result<()> {
let inner = |decryptor: &Self, buf: &mut [u8]| -> Result<()> {
fn verify_mac(data: &[u8], key: &HmacSha256Key, tag: &HmacSha256Output) -> Result<()> {
let mut mac = HmacSha256::new_from_slice(key)
Expand Down
2 changes: 1 addition & 1 deletion crates/scryptenc/src/encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<'m> Encryptor<'m> {
/// cipher.encrypt(&mut buf);
/// # assert_ne!(buf, data.as_slice());
/// ```
pub fn encrypt(&self, mut buf: impl AsMut<[u8]>) {
pub fn encrypt(&self, buf: &mut (impl AsMut<[u8]> + ?Sized)) {
let inner = |encryptor: &Self, buf: &mut [u8]| {
fn compute_mac(data: &[u8], key: &HmacSha256Key) -> HmacSha256Output {
let mut mac = HmacSha256::new_from_slice(key)
Expand Down

0 comments on commit 771daa9

Please sign in to comment.