Skip to content

Remove af_alg_iv::as_slice (which is unsound) and modify trait implementations that depended on it. #1892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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
17 changes: 3 additions & 14 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,20 +583,9 @@ cfg_if! {
}
}

impl af_alg_iv {
fn as_slice(&self) -> &[u8] {
unsafe {
::core::slice::from_raw_parts(
self.iv.as_ptr(),
self.ivlen as usize
)
}
}
}

impl PartialEq for af_alg_iv {
fn eq(&self, other: &af_alg_iv) -> bool {
*self.as_slice() == *other.as_slice()
self.ivlen == other.ivlen
}
}

Expand All @@ -605,14 +594,14 @@ cfg_if! {
impl ::fmt::Debug for af_alg_iv {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("af_alg_iv")
.field("iv", &self.as_slice())
.field("ivlen", &self.ivlen)
.finish()
}
}

impl ::hash::Hash for af_alg_iv {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.as_slice().hash(state);
self.ivlen.hash(state);
}
}
}
Expand Down
17 changes: 3 additions & 14 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,20 +781,9 @@ cfg_if! {
}
}

impl af_alg_iv {
fn as_slice(&self) -> &[u8] {
unsafe {
::core::slice::from_raw_parts(
self.iv.as_ptr(),
self.ivlen as usize
)
}
}
}

impl PartialEq for af_alg_iv {
fn eq(&self, other: &af_alg_iv) -> bool {
*self.as_slice() == *other.as_slice()
self.ivlen == other.ivlen
}
}

Expand All @@ -803,14 +792,14 @@ cfg_if! {
impl ::fmt::Debug for af_alg_iv {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("af_alg_iv")
.field("iv", &self.as_slice())
.field("ivlen", &self.ivlen)
.finish()
}
}

impl ::hash::Hash for af_alg_iv {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.as_slice().hash(state);
self.ivlen.hash(state);
}
}

Expand Down