Skip to content

Commit 11e33a9

Browse files
author
Gleb Pomykalov
committed
Implement traits for af_alg_iv
1 parent f210172 commit 11e33a9

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

src/unix/notbsd/android/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,34 @@ cfg_if! {
508508
self.salg_name.hash(state);
509509
}
510510
}
511+
512+
impl af_alg_iv {
513+
unsafe fn iv(&self) -> &[u8] {
514+
::std::slice::from_raw_parts(self.iv.as_ptr(), self.ivlen as usize)
515+
}
516+
}
517+
518+
impl PartialEq for af_alg_iv {
519+
fn eq(&self, other: &af_alg_iv) -> bool {
520+
*self.iv() == *other.iv()
521+
}
522+
}
523+
524+
impl Eq for af_alg_iv {}
525+
526+
impl ::fmt::Debug for af_alg_iv {
527+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
528+
f.debug_struct("af_alg_iv")
529+
.field("iv", self.iv())
530+
.finish()
531+
}
532+
}
533+
534+
impl ::hash::Hash for af_alg_iv {
535+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
536+
self.iv().hash(state);
537+
}
538+
}
511539
}
512540
}
513541

src/unix/notbsd/linux/mod.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,11 +507,6 @@ s! {
507507
pub cookie: ::uint32_t,
508508
pub len: ::uint32_t
509509
}
510-
511-
pub struct af_alg_iv {
512-
pub ivlen: u32,
513-
pub iv: [::c_uchar; 0],
514-
}
515510
}
516511

517512
s_no_extra_traits!{
@@ -539,6 +534,10 @@ s_no_extra_traits!{
539534
pub salg_name: [::c_uchar; 64],
540535
}
541536

537+
pub struct af_alg_iv {
538+
pub ivlen: u32,
539+
pub iv: [::c_uchar; 0],
540+
}
542541
}
543542

544543
cfg_if! {
@@ -685,7 +684,6 @@ cfg_if! {
685684
}
686685
}
687686

688-
689687
impl PartialEq for sockaddr_alg {
690688
fn eq(&self, other: &sockaddr_alg) -> bool {
691689
self.salg_family == other.salg_family
@@ -727,6 +725,34 @@ cfg_if! {
727725
self.salg_name.hash(state);
728726
}
729727
}
728+
729+
impl af_alg_iv {
730+
unsafe fn iv(&self) -> &[u8] {
731+
::std::slice::from_raw_parts(self.iv.as_ptr(), self.ivlen as usize)
732+
}
733+
}
734+
735+
impl PartialEq for af_alg_iv {
736+
fn eq(&self, other: &af_alg_iv) -> bool {
737+
*self.iv() == *other.iv()
738+
}
739+
}
740+
741+
impl Eq for af_alg_iv {}
742+
743+
impl ::fmt::Debug for af_alg_iv {
744+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
745+
f.debug_struct("af_alg_iv")
746+
.field("iv", self.iv())
747+
.finish()
748+
}
749+
}
750+
751+
impl ::hash::Hash for af_alg_iv {
752+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
753+
self.iv().hash(state);
754+
}
755+
}
730756
}
731757
}
732758

0 commit comments

Comments
 (0)