refactor: Apply cargo reccomended cleanups

This commit is contained in:
0xalivecow 2024-11-02 14:19:21 +01:00
parent 26ca12b419
commit 1ce30e1cea
No known key found for this signature in database
11 changed files with 12 additions and 21 deletions

View file

@ -1,5 +1,5 @@
use std::{ use std::{
env::{self, args}, env::{self},
fs, fs,
}; };

View file

@ -8,7 +8,7 @@ use tasks01::{
gfmul::gfmul_task, gfmul::gfmul_task,
poly2block::poly2block, poly2block::poly2block,
sea128::sea128, sea128::sea128,
xex::{self, fde_xex}, xex::{fde_xex},
}; };
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};

View file

@ -1,4 +1,4 @@
use crate::utils::poly::{b64_2_num, block_2_polynomial, get_coefficients}; use crate::utils::poly::block_2_polynomial;
use anyhow::Result; use anyhow::Result;
use base64::prelude::*; use base64::prelude::*;
use serde_json::Value; use serde_json::Value;
@ -19,7 +19,7 @@ pub fn block2poly(val: &Value) -> Result<Vec<u8>> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use serde_json::json; use serde_json::json;
use std::str::FromStr;
// Note this useful idiom: importing names from outer (for mod tests) scope. // Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*; use super::*;

View file

@ -1,7 +1,4 @@
use crate::utils::{ use crate::utils::poly::gfmul;
field::ByteArray,
poly::{b64_2_num, coefficient_to_binary, gfmul},
};
use anyhow::Result; use anyhow::Result;
use base64::prelude::*; use base64::prelude::*;
@ -24,7 +21,7 @@ pub fn gfmul_task(args: &Value) -> Result<Vec<u8>> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use serde_json::json; use serde_json::json;
use std::str::FromStr;
// Note this useful idiom: importing names from outer (for mod tests) scope. // Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*; use super::*;

View file

@ -1,6 +1,5 @@
use crate::utils::poly::{self, polynomial_2_block}; use crate::utils::poly::{polynomial_2_block};
use anyhow::{Ok, Result}; use anyhow::{Ok, Result};
use base64::prelude::*;
use serde_json::Value; use serde_json::Value;
pub fn poly2block(args: &Value) -> Result<Vec<u8>> { pub fn poly2block(args: &Value) -> Result<Vec<u8>> {

View file

@ -34,7 +34,7 @@ pub fn sea128(args: &Value) -> Result<String> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::fs;
use anyhow::Result; use anyhow::Result;
use serde_json::json; use serde_json::json;

View file

@ -1,4 +1,3 @@
use std::io::BufRead;
use anyhow::Result; use anyhow::Result;
use openssl::symm::{Cipher, Crypter, Mode}; use openssl::symm::{Cipher, Crypter, Mode};

View file

@ -101,7 +101,7 @@ impl ByteArray {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use std::fs;
#[test] #[test]
fn test_byte_array_shift1() { fn test_byte_array_shift1() {

View file

@ -1,7 +1,5 @@
use anyhow::{anyhow, Ok, Result}; use anyhow::{Ok, Result};
use base64::Engine;
use super::poly::gfmul;
pub fn xor_bytes(vec1: &Vec<u8>, mut vec2: Vec<u8>) -> Result<Vec<u8>> { pub fn xor_bytes(vec1: &Vec<u8>, mut vec2: Vec<u8>) -> Result<Vec<u8>> {
for (byte1, byte2) in vec1.iter().zip(vec2.iter_mut()) { for (byte1, byte2) in vec1.iter().zip(vec2.iter_mut()) {

View file

@ -28,7 +28,7 @@ pub fn parse_json(json: String) -> Result<Testcases> {
mod tests { mod tests {
use std::fs; use std::fs;
use serde_json::json;
// Note this useful idiom: importing names from outer (for mod tests) scope. // Note this useful idiom: importing names from outer (for mod tests) scope.
use super::*; use super::*;

View file

@ -1,10 +1,8 @@
use crate::utils::field::ByteArray; use crate::utils::field::ByteArray;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use base64::prelude::*; use base64::prelude::*;
use serde_json::Value;
use std::{str::FromStr, u128, u8, usize}; use std::{str::FromStr, u128, u8, usize};
use super::field;
pub const RED_POLY: u128 = 0x87000000_00000000_00000000_00000000; 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>> { pub fn gfmul(poly_a: Vec<u8>, poly_b: Vec<u8>, semantic: &str) -> Result<Vec<u8>> {
@ -167,7 +165,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]; 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 { for coeff in coeffs {
let block_num = coeff / 8; 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 byte_array