From 83af1a19a29d53744cfabf6620cd27373585ef4c Mon Sep 17 00:00:00 2001 From: K Shiva Kiran Date: Thu, 18 Apr 2024 19:41:01 +0530 Subject: [PATCH] algo/init(): Panic rather than Error incase of wrong parameters --- examples/encryption.rs | 2 +- examples/export.rs | 2 +- src/algo.rs | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/encryption.rs b/examples/encryption.rs index 26df7f6..77717f1 100644 --- a/examples/encryption.rs +++ b/examples/encryption.rs @@ -6,7 +6,7 @@ fn main() { let real_msg = "I have gathered intel regarding the government's illegal spying"; // Cipher initialization - let mut fb = FB128::init(10, 10).unwrap(); + let mut fb = FB128::init(10, 10); // Encryption (Adding messages is not limited to 2) let fake_key = fb.add(&fake_msg.as_bytes()); diff --git a/examples/export.rs b/examples/export.rs index de729b7..d3a32a1 100644 --- a/examples/export.rs +++ b/examples/export.rs @@ -2,7 +2,7 @@ use false_bottom::{FB128, FBKey, FBAlgo, Encode}; fn main() { // Cipher Initialization - let mut fb = FB128::init(18, 9).unwrap(); + let mut fb = FB128::init(18, 9); // Encryption let msg1 = "This is a message"; diff --git a/src/algo.rs b/src/algo.rs index 5554c62..48acea3 100644 --- a/src/algo.rs +++ b/src/algo.rs @@ -18,9 +18,9 @@ where /// Bounds: `2 <= keybase_len <= cipher_len` /// # Errors /// [InvalidParams](FBError::InvalidParams) - fn init(cipher_len: usize, keybase_len: usize) -> Result, FBError> { + fn init(cipher_len: usize, keybase_len: usize) -> FBObj { if cipher_len < keybase_len || keybase_len < 2 { - return Err(FBError::InvalidParams); + panic!("{}", FBError::InvalidParams); } let mut rng = rand::thread_rng(); let r = (0..keybase_len) @@ -31,7 +31,7 @@ where .collect(); let c = RwLock::new(c_vec); - Ok(FBObj { c, r }) + FBObj {c, r} } /// Adds the provided message to the ciphertext. @@ -115,7 +115,7 @@ where fn encrypt_u128() { use crypto_bigint::U128; let msg = U128::from_u32(100); - let fb = FBObj::::init(18, 12).unwrap(); + let fb = FBObj::::init(18, 12); let rng = &mut rand::thread_rng(); let key = fb.add_block(rng, &msg); let decrypted = fb.decrypt_block(&key).unwrap(); @@ -127,7 +127,7 @@ fn encrypt_bytes() { use crypto_bigint::U128; let input1 = vec![255_u8; 33]; let input2 = vec![0_u8; 102]; - let mut fb = FBObj::::init(21, 9).unwrap(); + let mut fb = FBObj::::init(21, 9); let key1 = fb.add(&input1); let key2 = fb.add(&input2); let decr1 = fb.decrypt(&key1).unwrap();