From 11e33a9a5563caa98ed20867b6fede60b3f66609 Mon Sep 17 00:00:00 2001 From: Gleb Pomykalov Date: Mon, 18 Feb 2019 22:22:03 +0300 Subject: [PATCH] Implement traits for af_alg_iv --- src/unix/notbsd/android/mod.rs | 28 +++++++++++++++++++++++++ src/unix/notbsd/linux/mod.rs | 38 ++++++++++++++++++++++++++++------ 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index 00a0d5fc..5e64ac35 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -508,6 +508,34 @@ cfg_if! { self.salg_name.hash(state); } } + + impl af_alg_iv { + unsafe fn iv(&self) -> &[u8] { + ::std::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.iv() == *other.iv() + } + } + + impl Eq for af_alg_iv {} + + 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.iv()) + .finish() + } + } + + impl ::hash::Hash for af_alg_iv { + fn hash(&self, state: &mut H) { + self.iv().hash(state); + } + } } } diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index 2e7d9d9d..c41e1a02 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -507,11 +507,6 @@ s! { pub cookie: ::uint32_t, pub len: ::uint32_t } - - pub struct af_alg_iv { - pub ivlen: u32, - pub iv: [::c_uchar; 0], - } } s_no_extra_traits!{ @@ -539,6 +534,10 @@ s_no_extra_traits!{ pub salg_name: [::c_uchar; 64], } + pub struct af_alg_iv { + pub ivlen: u32, + pub iv: [::c_uchar; 0], + } } cfg_if! { @@ -685,7 +684,6 @@ cfg_if! { } } - impl PartialEq for sockaddr_alg { fn eq(&self, other: &sockaddr_alg) -> bool { self.salg_family == other.salg_family @@ -727,6 +725,34 @@ cfg_if! { self.salg_name.hash(state); } } + + impl af_alg_iv { + unsafe fn iv(&self) -> &[u8] { + ::std::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.iv() == *other.iv() + } + } + + impl Eq for af_alg_iv {} + + 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.iv()) + .finish() + } + } + + impl ::hash::Hash for af_alg_iv { + fn hash(&self, state: &mut H) { + self.iv().hash(state); + } + } } }