Skip to content

Commit 67ba267

Browse files
committed
fix: resolve clippy lint errors
1 parent 5fd12fc commit 67ba267

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

src/okuchi.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Okuchi {
6262

6363
// If data is empty, encrypt a single zero-block so decrypt can distinguish empty vs missing.
6464
if bytes.is_empty() {
65-
let c = Self::encrypt(pub_key, &[])?;
65+
let c = Self::encrypt(pub_key, [])?;
6666
blocks.push(c.to_bytes());
6767
}
6868

@@ -242,7 +242,7 @@ impl Okuchi {
242242
// conservative estimate of p bits
243243
let p_bits = n_bits / 3;
244244
// ensure at least 1 byte available
245-
let bytes = (p_bits.saturating_sub(1) / 8) as usize;
245+
let bytes = p_bits.saturating_sub(1) / 8;
246246
// require at least 1 byte
247247
std::cmp::max(1, bytes)
248248
}
@@ -264,8 +264,8 @@ mod tests {
264264
let msg = "Testing OU encryption";
265265

266266
// Use packed stream API for arbitrary UTF-8
267-
let packed = Okuchi::encrypt_stream(&pub_key, msg).unwrap();
268-
let decrypted_bytes = Okuchi::decrypt_stream(&priv_key, &packed).unwrap();
267+
let packed = Okuchi::encrypt_stream(pub_key, msg).unwrap();
268+
let decrypted_bytes = Okuchi::decrypt_stream(priv_key, &packed).unwrap();
269269

270270
let decrypted = String::from_utf8(decrypted_bytes).expect("decrypted not valid UTF-8");
271271
assert_eq!(decrypted, msg);
@@ -280,8 +280,8 @@ mod tests {
280280
// make a long message that will definitely exceed a single block
281281
let msg = "Rust cryptography long text test".repeat(50);
282282

283-
let packed = Okuchi::encrypt_stream(&pub_key, &msg).unwrap();
284-
let decrypted_bytes = Okuchi::decrypt_stream(&priv_key, &packed).unwrap();
283+
let packed = Okuchi::encrypt_stream(pub_key, &msg).unwrap();
284+
let decrypted_bytes = Okuchi::decrypt_stream(priv_key, &packed).unwrap();
285285

286286
let decrypted = String::from_utf8(decrypted_bytes).expect("decrypted not valid UTF-8");
287287
assert_eq!(decrypted, msg);
@@ -298,13 +298,13 @@ mod tests {
298298
let m1 = BigUint::from(50u32);
299299
let m2 = BigUint::from(25u32);
300300

301-
let packed1 = Okuchi::encrypt_stream(&pub_key, m1.to_bytes_be()).unwrap();
302-
let packed2 = Okuchi::encrypt_stream(&pub_key, m2.to_bytes_be()).unwrap();
301+
let packed1 = Okuchi::encrypt_stream(pub_key, m1.to_bytes_be()).unwrap();
302+
let packed2 = Okuchi::encrypt_stream(pub_key, m2.to_bytes_be()).unwrap();
303303

304304
// homomorphically add the two packed streams (block by block)
305-
let packed_sum = Okuchi::homomorphic_add_packed(&pub_key, &packed1, &packed2).unwrap();
305+
let packed_sum = Okuchi::homomorphic_add_packed(pub_key, &packed1, &packed2).unwrap();
306306

307-
let decrypted_sum_bytes = Okuchi::decrypt_stream(&priv_key, &packed_sum).unwrap();
307+
let decrypted_sum_bytes = Okuchi::decrypt_stream(priv_key, &packed_sum).unwrap();
308308
let decrypted_sum_bn = BigUint::from_bytes_be(&decrypted_sum_bytes);
309309

310310
let expected = &m1 + &m2;
@@ -331,7 +331,7 @@ mod tests {
331331
let keypair = KeyPair::new(512).unwrap();
332332
let message = "hello world!";
333333

334-
let ciphertext = Okuchi::encrypt(keypair.pub_key(), &message).unwrap();
334+
let ciphertext = Okuchi::encrypt(keypair.pub_key(), message).unwrap();
335335
let decrypted = Okuchi::decrypt(keypair.priv_key(), &ciphertext).unwrap();
336336

337337
assert_eq!(message.as_bytes(), decrypted);
@@ -378,8 +378,8 @@ mod tests {
378378
let keypair = KeyPair::new(512).unwrap();
379379
let message = "Hello world";
380380

381-
let c1 = Okuchi::encrypt(keypair.pub_key(), &message).unwrap();
382-
let c2 = Okuchi::encrypt(keypair.pub_key(), &message).unwrap();
381+
let c1 = Okuchi::encrypt(keypair.pub_key(), message).unwrap();
382+
let c2 = Okuchi::encrypt(keypair.pub_key(), message).unwrap();
383383

384384
// different random r values MUST produce different ciphertexts
385385
assert_ne!(c1.value(), c2.value());
@@ -390,7 +390,7 @@ mod tests {
390390
let keypair = KeyPair::new(512).unwrap();
391391
let too_large = keypair.pub_key().n() + BigUint::one();
392392

393-
let result = Okuchi::encrypt(keypair.pub_key(), &too_large.to_bytes_be());
393+
let result = Okuchi::encrypt(keypair.pub_key(), too_large.to_bytes_be());
394394
assert!(matches!(result, Err(Error::PlaintextTooLarge)));
395395
}
396396

@@ -421,7 +421,7 @@ mod tests {
421421
let keypair = KeyPair::new(512).unwrap();
422422
let message = BigUint::zero();
423423

424-
let c = Okuchi::encrypt(keypair.pub_key(), &message.to_bytes_be()).unwrap();
424+
let c = Okuchi::encrypt(keypair.pub_key(), message.to_bytes_be()).unwrap();
425425
let decrypted = Okuchi::decrypt(keypair.priv_key(), &c).unwrap();
426426

427427
assert_eq!(message, BigUint::from_bytes_be(&decrypted));
@@ -437,14 +437,14 @@ mod tests {
437437
let m2 = BigUint::from(20u32);
438438
let m3 = BigUint::from(30u32);
439439

440-
let c1 = Okuchi::encrypt(&pub_key, &m1.to_bytes_be()).unwrap();
441-
let c2 = Okuchi::encrypt(&pub_key, &m2.to_bytes_be()).unwrap();
442-
let c3 = Okuchi::encrypt(&pub_key, &m3.to_bytes_be()).unwrap();
440+
let c1 = Okuchi::encrypt(pub_key, m1.to_bytes_be()).unwrap();
441+
let c2 = Okuchi::encrypt(pub_key, m2.to_bytes_be()).unwrap();
442+
let c3 = Okuchi::encrypt(pub_key, m3.to_bytes_be()).unwrap();
443443

444444
let c_prod = &(&c1 * &c2) * &c3;
445445
let c_final = Ciphertext::new(c_prod.value() % pub_key.n());
446446

447-
let decrypted = Okuchi::decrypt(&priv_key, &c_final).unwrap();
447+
let decrypted = Okuchi::decrypt(priv_key, &c_final).unwrap();
448448
let expected = (&m1 + &m2 + &m3) % &priv_key.p;
449449

450450
assert_eq!(expected.to_bytes_be(), decrypted);

tests/integration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)