refactor: apply rust suggested code cleanups
This commit is contained in:
parent
68d9f13a3d
commit
9785b8d8aa
12 changed files with 16 additions and 40 deletions
|
|
@ -1,6 +1,4 @@
|
|||
use std::{io::BufRead, process::Output};
|
||||
|
||||
use crate::utils::{field::ByteArray, math::reverse_bits_in_bytevec, poly::gfmul};
|
||||
use crate::utils::{field::ByteArray, poly::gfmul};
|
||||
use anyhow::Result;
|
||||
use base64::prelude::*;
|
||||
use openssl::symm::{Cipher, Crypter, Mode};
|
||||
|
|
@ -40,7 +38,6 @@ pub fn aes_128_decrypt(key: &Vec<u8>, input: &Vec<u8>) -> Result<Vec<u8>> {
|
|||
|
||||
let mut bytes: [u8; 16] = [0u8; 16];
|
||||
bytes.copy_from_slice(&plaintext);
|
||||
let number: u128 = <u128>::from_be_bytes(bytes);
|
||||
|
||||
Ok(plaintext)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
use std::{
|
||||
env::args,
|
||||
ops::{Add, BitXor, Div, Mul, Rem, Sub},
|
||||
result,
|
||||
};
|
||||
use std::ops::{Add, BitXor, Div, Mul, Sub};
|
||||
|
||||
use anyhow::{anyhow, Ok, Result};
|
||||
use base64::prelude::*;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::{tasks::tasks01::poly2block::poly2block, utils::poly::polynomial_2_block};
|
||||
use crate::utils::poly::polynomial_2_block;
|
||||
|
||||
use super::{math::xor_bytes, poly::gfmul};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
use anyhow::{anyhow, Ok, Result};
|
||||
use base64::Engine;
|
||||
use anyhow::{Ok, Result};
|
||||
|
||||
use super::poly::gfmul;
|
||||
|
||||
pub fn xor_bytes(vec1: &Vec<u8>, mut vec2: Vec<u8>) -> Result<Vec<u8>> {
|
||||
for (byte1, byte2) in vec1.iter().zip(vec2.iter_mut()) {
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@ pub fn parse_json(json: String) -> Result<Testcases> {
|
|||
mod tests {
|
||||
use std::fs;
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
// Note this useful idiom: importing names from outer (for mod tests) scope.
|
||||
use super::*;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
use crate::utils::field::ByteArray;
|
||||
use anyhow::{anyhow, Result};
|
||||
use base64::prelude::*;
|
||||
use serde_json::Value;
|
||||
use std::{str::FromStr, u128, u8, usize};
|
||||
|
||||
use super::{field, math::reverse_bits_in_bytevec};
|
||||
pub const RED_POLY: u128 = 0x87000000_00000000_00000000_00000000;
|
||||
|
||||
pub fn gfmul(poly_a: &Vec<u8>, poly_b: &Vec<u8>, semantic: &str) -> Result<Vec<u8>> {
|
||||
|
|
@ -172,7 +170,7 @@ pub fn coefficients_to_byte_arr_xex(coeffs: Vec<u8>) -> Vec<u8> {
|
|||
let mut byte_array: Vec<u8> = vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
for coeff in coeffs {
|
||||
let block_num = coeff / 8;
|
||||
byte_array[usize::from(block_num)] |= (1 << (coeff % 7));
|
||||
byte_array[usize::from(block_num)] |= 1 << (coeff % 7);
|
||||
}
|
||||
|
||||
byte_array
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue