Skip to content

Commit

Permalink
Use split_reserved from inout and restore forbid(unsafe_code)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Nov 20, 2024
1 parent 472a462 commit aca70a0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 2 additions & 17 deletions aead/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg"
)]
// #![forbid(unsafe_code)]
#![forbid(unsafe_code)]
#![warn(
clippy::unwrap_used,
// missing_docs,
Expand Down Expand Up @@ -169,7 +169,7 @@ pub trait Aead {
associated_data: &[u8],
mut buffer: InOutBufReserved<'_, 'out, u8>,
) -> Result<&'out mut [u8]> {
let (msg, tail) = split_reserved(&mut buffer);
let (msg, tail) = buffer.split_reserved();
let tag_len = Self::TagSize::USIZE;
let tag_dst = tail.get_mut(..tag_len).ok_or(Error)?;
let res_len = msg.len() + tag_len;
Expand Down Expand Up @@ -459,21 +459,6 @@ pub trait Aead {
}
}

// TODO: move to `inout`
fn split_reserved<'a>(
buf: &'a mut InOutBufReserved<'_, '_, u8>,
) -> (InOutBuf<'a, 'a, u8>, &'a mut [u8]) {
let in_len = buf.get_in_len();
let out_len = buf.get_out_len();
let in_ptr = buf.get_in().as_ptr();
let out_ptr = buf.get_out().as_mut_ptr();
unsafe {
let body = InOutBuf::from_raw(in_ptr, out_ptr, in_len);
let tail = core::slice::from_raw_parts_mut(out_ptr.add(in_len), out_len - in_len);
(body, tail)
}
}

/// AEAD payloads (message + AAD).
///
/// Combination of a message (plaintext or ciphertext) and
Expand Down

0 comments on commit aca70a0

Please sign in to comment.