Skip to content

Commit 5b221b2

Browse files
committed
Re-add trait implementations of af_alg_iv and mark them as deprecated.
1 parent 4b6ffb7 commit 5b221b2

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/unix/linux_like/android/mod.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ s_no_extra_traits! {
306306
pub salg_name: [::c_uchar; 64],
307307
}
308308

309+
/// WARNING: The `PartialEq`, `Eq` and `Hash` implementations of this
310+
/// type are unsound and will be removed in the future.
309311
pub struct af_alg_iv {
310312
pub ivlen: u32,
311313
pub iv: [::c_uchar; 0],
@@ -591,13 +593,47 @@ cfg_if! {
591593
}
592594
}
593595

596+
impl af_alg_iv {
597+
fn as_slice(&self) -> &[u8] {
598+
unsafe {
599+
::core::slice::from_raw_parts(
600+
self.iv.as_ptr(),
601+
self.ivlen as usize
602+
)
603+
}
604+
}
605+
}
606+
607+
#[deprecated(
608+
note = "this trait implementation is unsound and will be removed"
609+
)]
610+
impl PartialEq for af_alg_iv {
611+
fn eq(&self, other: &af_alg_iv) -> bool {
612+
*self.as_slice() == *other.as_slice()
613+
}
614+
}
615+
616+
#[deprecated(
617+
note = "this trait implementation is unsound and will be removed"
618+
)]
619+
impl Eq for af_alg_iv {}
620+
594621
impl ::fmt::Debug for af_alg_iv {
595622
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
596623
f.debug_struct("af_alg_iv")
597624
.field("ivlen", &self.ivlen)
598625
.finish()
599626
}
600627
}
628+
629+
#[deprecated(
630+
note = "this trait implementation is unsound and will be removed"
631+
)]
632+
impl ::hash::Hash for af_alg_iv {
633+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
634+
self.as_slice().hash(state);
635+
}
636+
}
601637
}
602638
}
603639

src/unix/linux_like/linux/mod.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ s_no_extra_traits! {
538538
pub salg_name: [::c_uchar; 64],
539539
}
540540

541+
/// WARNING: The `PartialEq`, `Eq` and `Hash` implementations of this
542+
/// type are unsound and will be removed in the future.
541543
pub struct af_alg_iv {
542544
pub ivlen: u32,
543545
pub iv: [::c_uchar; 0],
@@ -781,6 +783,31 @@ cfg_if! {
781783
}
782784
}
783785

786+
impl af_alg_iv {
787+
fn as_slice(&self) -> &[u8] {
788+
unsafe {
789+
::core::slice::from_raw_parts(
790+
self.iv.as_ptr(),
791+
self.ivlen as usize
792+
)
793+
}
794+
}
795+
}
796+
797+
#[deprecated(
798+
note = "this trait implementation is unsound and will be removed"
799+
)]
800+
impl PartialEq for af_alg_iv {
801+
fn eq(&self, other: &af_alg_iv) -> bool {
802+
*self.as_slice() == *other.as_slice()
803+
}
804+
}
805+
806+
#[deprecated(
807+
note = "this trait implementation is unsound and will be removed"
808+
)]
809+
impl Eq for af_alg_iv {}
810+
784811
impl ::fmt::Debug for af_alg_iv {
785812
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
786813
f.debug_struct("af_alg_iv")
@@ -789,6 +816,15 @@ cfg_if! {
789816
}
790817
}
791818

819+
#[deprecated(
820+
note = "this trait implementation is unsound and will be removed"
821+
)]
822+
impl ::hash::Hash for af_alg_iv {
823+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
824+
self.as_slice().hash(state);
825+
}
826+
}
827+
792828
impl PartialEq for mq_attr {
793829
fn eq(&self, other: &mq_attr) -> bool {
794830
self.mq_flags == other.mq_flags &&

0 commit comments

Comments
 (0)