algo/init(): Panic rather than Error incase of wrong parameters

This commit is contained in:
K Shiva Kiran 2024-04-18 19:41:01 +05:30
parent e0915ab25c
commit 83af1a19a2
3 changed files with 7 additions and 7 deletions

View File

@ -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());

View File

@ -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";

View File

@ -18,9 +18,9 @@ where
/// Bounds: `2 <= keybase_len <= cipher_len`
/// # Errors
/// [InvalidParams](FBError::InvalidParams)
fn init(cipher_len: usize, keybase_len: usize) -> Result<FBObj<T>, FBError> {
fn init(cipher_len: usize, keybase_len: usize) -> FBObj<T> {
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::<U128>::init(18, 12).unwrap();
let fb = FBObj::<U128>::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::<U128>::init(21, 9).unwrap();
let mut fb = FBObj::<U128>::init(21, 9);
let key1 = fb.add(&input1);
let key2 = fb.add(&input2);
let decr1 = fb.decrypt(&key1).unwrap();