Skip to content

Commit a73c668

Browse files
committed
Fix clippy lints
1 parent 90ca4dc commit a73c668

File tree

14 files changed

+80
-29
lines changed

14 files changed

+80
-29
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ inherits = "release"
5757
codegen-units = 1
5858
inherits = "release"
5959
lto = "fat"
60+
61+
[workspace.lints.clippy]
62+
unwrap_used = "warn"

cryprot-codes/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ repository.workspace = true
1313
bench-libote = ["dep:libote-codes"]
1414
libote-compat = ["dep:libote-codes"]
1515

16+
[lints]
17+
workspace = true
18+
1619
[lib]
1720
bench = false
1821

cryprot-codes/src/ex_conv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl ExConvCode {
269269
#[cfg(debug_assertions)]
270270
for (i, bb) in bb.iter().enumerate() {
271271
let exp = if ((b >> i) & 1) != 0 { xi } else { Block::ZERO };
272-
debug_assert_eq!(exp, bytemuck::cast(*bb))
272+
debug_assert_eq!(exp, bytemuck::cast(*bb));
273273
}
274274

275275
seq!(N in 0..8 {

cryprot-core/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ version = "0.2.0"
99
authors.workspace = true
1010
repository.workspace = true
1111

12+
[lints]
13+
workspace = true
14+
1215
[lib]
1316
bench = false
1417

cryprot-core/src/aes_hash.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl AesHash {
8585
for chunk in x.chunks_mut(AES_PAR_BLOCKS) {
8686
self.aes
8787
.encrypt_blocks_b2b(bytemuck::cast_slice(chunk), &mut tmp[..chunk.len()])
88-
.unwrap();
88+
.expect("in and out always have same length");
8989
chunk
9090
.iter_mut()
9191
.zip(tmp)
@@ -101,7 +101,7 @@ impl AesHash {
101101
for (chunk_idx, chunk) in x.chunks_mut(AES_PAR_BLOCKS).enumerate() {
102102
self.aes
103103
.encrypt_blocks_b2b(bytemuck::cast_slice(chunk), &mut tmp[..chunk.len()])
104-
.unwrap();
104+
.expect("in and out always have same length");
105105
chunk
106106
.iter_mut()
107107
.zip(&mut tmp)

cryprot-core/src/block/gf128.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ mod clmul {
118118
#[inline]
119119
pub unsafe fn clmul128(a: __m128i, b: __m128i) -> (__m128i, __m128i) {
120120
// This is currently needed because we run the nightly version of
121-
// clippy where this is an unused unsafe because the used
121+
// clippy where this is an unused unsafe because the used
122122
// intrinsincs have been marked safe on nightly but not yet on
123123
// stable.
124124
#[allow(unused_unsafe)]

cryprot-core/src/transpose/avx2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ const AVX_BLOCK_SHIFT: usize = 4;
153153
const AVX_BLOCK_SIZE: usize = 1 << AVX_BLOCK_SHIFT;
154154

155155
/// Transpose 128x128 bit matrix using AVX2.
156-
///
156+
///
157157
/// # Safety
158158
/// AVX2 needs to be enabled.
159159
#[target_feature(enable = "avx2")]

cryprot-net/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ repository.workspace = true
1313
__testing = ["dep:anyhow", "metrics"]
1414
metrics = ["dep:tracing-subscriber", "serde/derive"]
1515

16+
[lints]
17+
workspace = true
18+
1619
[dependencies]
1720
anyhow = { workspace = true, optional = true }
1821
bincode.workspace = true

cryprot-ot/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ version = "0.2.0"
99
authors.workspace = true
1010
repository.workspace = true
1111

12+
[lints]
13+
workspace = true
14+
1215
[lib]
1316
# https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
1417
bench = false

cryprot-ot/src/adapter.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
//! Adapters for OT types.
22
3+
use std::io;
4+
35
use bitvec::{order::Lsb0, vec::BitVec};
46
use cryprot_core::{Block, buf::Buf};
57
use cryprot_net::ConnectionError;
68
use futures::{SinkExt, StreamExt};
79
use subtle::ConditionallySelectable;
10+
use thiserror::Error;
811
use tokio::io::{AsyncReadExt, AsyncWriteExt};
912

1013
use crate::{
@@ -38,8 +41,20 @@ impl<P: SemiHonest> SemiHonest for ChosenChoice<P> {}
3841
// TODO is there something I can cite that this holds?
3942
impl<P: Malicious> Malicious for ChosenChoice<P> {}
4043

44+
#[derive(Error, Debug)]
45+
pub enum Error<E> {
46+
#[error("unable to perform R-OTs")]
47+
Rot(E),
48+
#[error("error in sending correction values for C-OT")]
49+
Correction(io::Error),
50+
#[error("expected correction values but receiver is closed")]
51+
MissingCorrection,
52+
#[error("connection error to peer")]
53+
Connecion(#[from] ConnectionError),
54+
}
55+
4156
impl<R: RandChoiceRotReceiver> RotReceiver for ChosenChoice<R> {
42-
type Error = R::Error;
57+
type Error = Error<R::Error>;
4358

4459
async fn receive_into(
4560
&mut self,
@@ -50,30 +65,33 @@ impl<R: RandChoiceRotReceiver> RotReceiver for ChosenChoice<R> {
5065
.0
5166
.rand_choice_receive_into(ots)
5267
.await
53-
.map_err(|_| ())
54-
.unwrap();
68+
.map_err(Error::Rot)?;
5569
for (c1, c2) in rand_choices.iter_mut().zip(choices) {
5670
*c1 ^= *c2;
5771
}
5872
let mut bv: BitVec<u8, Lsb0> = BitVec::with_capacity(choices.len());
5973
bv.extend(rand_choices.iter().map(|c| c.unwrap_u8() != 0));
6074

61-
let (mut tx, _) = self.connection().stream().await.unwrap();
62-
tx.send(bv).await.unwrap();
75+
let (mut tx, _) = self.connection().stream().await?;
76+
tx.send(bv).await.map_err(Error::Correction)?;
6377
Ok(())
6478
}
6579
}
6680

6781
impl<S: RotSender + RandChoiceRotSender + Send> RotSender for ChosenChoice<S> {
68-
type Error = S::Error;
82+
type Error = Error<S::Error>;
6983

7084
async fn send_into(
7185
&mut self,
7286
ots: &mut impl cryprot_core::buf::Buf<[cryprot_core::Block; 2]>,
7387
) -> Result<(), Self::Error> {
74-
self.0.send_into(ots).await.map_err(|_| ()).unwrap();
75-
let (_, mut rx) = self.connection().stream().await.unwrap();
76-
let correction: BitVec<u8, Lsb0> = rx.next().await.unwrap().unwrap();
88+
self.0.send_into(ots).await.map_err(Error::Rot)?;
89+
let (_, mut rx) = self.connection().stream().await?;
90+
let correction: BitVec<u8, Lsb0> = rx
91+
.next()
92+
.await
93+
.ok_or(Error::MissingCorrection)?
94+
.map_err(Error::Correction)?;
7795

7896
for (ots, c_bit) in ots.iter_mut().zip(correction) {
7997
let tmp = *ots;

0 commit comments

Comments
 (0)