Skip to content

Commit a0ad1f4

Browse files
committed
block-padding: remove unsafe code
1 parent 014d8f0 commit a0ad1f4

File tree

3 files changed

+58
-58
lines changed

3 files changed

+58
-58
lines changed

Cargo.lock

Lines changed: 53 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

block-padding/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ categories = ["cryptography", "no-std"]
1313
readme = "README.md"
1414

1515
[dependencies]
16-
hybrid-array = "0.4"
16+
hybrid-array = "0.4.2"

block-padding/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
99
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
1010
)]
11+
#![deny(unsafe_code)]
1112
#![warn(missing_docs)]
1213

1314
pub use hybrid_array as array;
@@ -64,7 +65,7 @@ pub trait Padding {
6465
/// Unpad data in the `blocks`.
6566
///
6667
/// Returns `Err(UnpadError)` if the block contains malformed padding.
67-
fn unpad_blocks<BlockSize: ArraySize>(
68+
fn unpad_blocks<const N: usize, BlockSize: ArraySize<ArrayType<u8> = [u8; N]>>(
6869
blocks: &[Array<u8, BlockSize>],
6970
) -> Result<&[u8], UnpadError> {
7071
let bs = BlockSize::USIZE;
@@ -78,11 +79,8 @@ pub trait Padding {
7879
(None, PadType::Ambiguous) => 0,
7980
(None, PadType::Reversible) => return Err(UnpadError),
8081
};
81-
// SAFETY: `res_len` is always smaller or equal to `bs * blocks.len()`
82-
Ok(unsafe {
83-
let p = blocks.as_ptr() as *const u8;
84-
core::slice::from_raw_parts(p, res_len)
85-
})
82+
let data = Array::slice_as_flattened(blocks);
83+
Ok(&data[..res_len])
8684
}
8785
}
8886

0 commit comments

Comments
 (0)