Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion block-padding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ categories = ["cryptography", "no-std"]
readme = "README.md"

[dependencies]
hybrid-array = "0.4"
hybrid-array = "0.4.3"
9 changes: 4 additions & 5 deletions block-padding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
)]
#![forbid(unsafe_code)]
#![warn(missing_docs)]

pub use hybrid_array as array;
Expand Down Expand Up @@ -78,11 +79,9 @@ pub trait Padding {
(None, PadType::Ambiguous) => 0,
(None, PadType::Reversible) => return Err(UnpadError),
};
// SAFETY: `res_len` is always smaller or equal to `bs * blocks.len()`
Ok(unsafe {
let p = blocks.as_ptr() as *const u8;
core::slice::from_raw_parts(p, res_len)
})

// Note: `res_len` is always smaller or equal to `bs * blocks.len()`
Ok(&Array::slice_as_flattened(blocks)[..res_len])
Comment on lines +83 to +84
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could do something like this instead?

Suggested change
// Note: `res_len` is always smaller or equal to `bs * blocks.len()`
Ok(&Array::slice_as_flattened(blocks)[..res_len])
Array::slice_as_flattened(blocks).get(..res_len).ok_or(UnpadError)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If res_len is bigger than data.len() than it's a bug, so we should panic.

}
}

Expand Down
Loading