crypto_bigint/uint/boxed/
bit_or.rs1use crate::{BoxedUint, Wrapping};
4use core::ops::{BitOr, BitOrAssign};
5use subtle::{Choice, CtOption};
6
7impl BoxedUint {
8 #[inline(always)]
10 pub fn bitor(&self, rhs: &Self) -> Self {
11 Self::map_limbs(self, rhs, |a, b| a.bitor(b))
12 }
13
14 pub fn wrapping_or(&self, rhs: &Self) -> Self {
19 self.bitor(rhs)
20 }
21
22 pub fn checked_or(&self, rhs: &Self) -> CtOption<Self> {
24 let result = self.bitor(rhs);
25 CtOption::new(result, Choice::from(1))
26 }
27}
28
29impl BitOr for BoxedUint {
30 type Output = Self;
31
32 fn bitor(self, rhs: Self) -> BoxedUint {
33 self.bitor(&rhs)
34 }
35}
36
37impl BitOr<&BoxedUint> for BoxedUint {
38 type Output = BoxedUint;
39
40 #[allow(clippy::needless_borrow)]
41 fn bitor(self, rhs: &BoxedUint) -> BoxedUint {
42 (&self).bitor(rhs)
43 }
44}
45
46impl BitOr<BoxedUint> for &BoxedUint {
47 type Output = BoxedUint;
48
49 fn bitor(self, rhs: BoxedUint) -> BoxedUint {
50 self.bitor(&rhs)
51 }
52}
53
54impl BitOr<&BoxedUint> for &BoxedUint {
55 type Output = BoxedUint;
56
57 fn bitor(self, rhs: &BoxedUint) -> BoxedUint {
58 self.bitor(rhs)
59 }
60}
61
62impl BitOrAssign for BoxedUint {
63 fn bitor_assign(&mut self, other: Self) {
64 Self::bitor_assign(self, &other)
65 }
66}
67
68impl BitOrAssign<&BoxedUint> for BoxedUint {
69 fn bitor_assign(&mut self, other: &Self) {
70 for (a, b) in self.limbs.iter_mut().zip(other.limbs.iter()) {
71 *a |= *b;
72 }
73 }
74}
75
76impl BitOr for Wrapping<BoxedUint> {
77 type Output = Self;
78
79 fn bitor(self, rhs: Self) -> Wrapping<BoxedUint> {
80 Wrapping(self.0.bitor(&rhs.0))
81 }
82}
83
84impl BitOr<&Wrapping<BoxedUint>> for Wrapping<BoxedUint> {
85 type Output = Wrapping<BoxedUint>;
86
87 fn bitor(self, rhs: &Wrapping<BoxedUint>) -> Wrapping<BoxedUint> {
88 Wrapping(self.0.bitor(&rhs.0))
89 }
90}
91
92impl BitOr<Wrapping<BoxedUint>> for &Wrapping<BoxedUint> {
93 type Output = Wrapping<BoxedUint>;
94
95 fn bitor(self, rhs: Wrapping<BoxedUint>) -> Wrapping<BoxedUint> {
96 Wrapping(BoxedUint::bitor(&self.0, &rhs.0))
97 }
98}
99
100impl BitOr<&Wrapping<BoxedUint>> for &Wrapping<BoxedUint> {
101 type Output = Wrapping<BoxedUint>;
102
103 fn bitor(self, rhs: &Wrapping<BoxedUint>) -> Wrapping<BoxedUint> {
104 Wrapping(BoxedUint::bitor(&self.0, &rhs.0))
105 }
106}
107
108impl BitOrAssign for Wrapping<BoxedUint> {
109 fn bitor_assign(&mut self, other: Self) {
110 self.0.bitor_assign(&other.0)
111 }
112}
113
114impl BitOrAssign<&Wrapping<BoxedUint>> for Wrapping<BoxedUint> {
115 fn bitor_assign(&mut self, other: &Self) {
116 self.0.bitor_assign(&other.0)
117 }
118}