Skip to content

Commit 7084f59

Browse files
committed
block-padding: remove unsafe usage
Pushes the unsafety down to the `hybrid-array` level, using the newly added `Array::slice_as_flattened`. Also adds `forbid(unsafe_code)`.
1 parent 014d8f0 commit 7084f59

3 files changed

Lines changed: 11 additions & 12 deletions

File tree

Cargo.lock

Lines changed: 6 additions & 6 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.3"

block-padding/src/lib.rs

Lines changed: 4 additions & 5 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+
#![forbid(unsafe_code)]
1112
#![warn(missing_docs)]
1213

1314
pub use hybrid_array as array;
@@ -78,11 +79,9 @@ 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+
83+
// Note: `res_len` is always smaller or equal to `bs * blocks.len()`
84+
Ok(&Array::slice_as_flattened(blocks)[..res_len])
8685
}
8786
}
8887

0 commit comments

Comments
 (0)