Skip to content

Commit 3b89259

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 3b89259

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ exclude = ["aarch64-dit"]
2020

2121
[profile.dev]
2222
opt-level = 2
23+
24+
[patch.crates-io]
25+
hybrid-array = { git = "https://github.com/RustCrypto/hybrid-array" }

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)