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,11 +1,8 @@
|
|||
use base64::prelude::*;
|
||||
|
||||
use std::{collections::HashMap, env::args};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::utils::{
|
||||
ciphers::gcm_encrypt_aes,
|
||||
parse::{Responses, Testcase, Testcases},
|
||||
};
|
||||
use crate::utils::parse::{Responses, Testcase, Testcases};
|
||||
use tasks01::{
|
||||
block2poly::block2poly,
|
||||
gcm::{gcm_decrypt, gcm_encrypt},
|
||||
|
|
@ -14,7 +11,7 @@ use tasks01::{
|
|||
pfmath::{gfdiv, gfpoly_add, gfpoly_divmod, gfpoly_mul, gfpoly_pow, gfpoly_powmod},
|
||||
poly2block::poly2block,
|
||||
sea128::sea128,
|
||||
xex::{self, fde_xex},
|
||||
xex::{fde_xex},
|
||||
};
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
|
|
|
|||
|
|
@ -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 base64::prelude::*;
|
||||
use serde_json::Value;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
use crate::utils::{
|
||||
field::ByteArray,
|
||||
poly::{b64_2_num, coefficient_to_binary, gfmul},
|
||||
};
|
||||
use crate::utils::poly::gfmul;
|
||||
|
||||
use anyhow::Result;
|
||||
use base64::prelude::*;
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ use base64::prelude::*;
|
|||
use serde_json::Value;
|
||||
use std::io::prelude::*;
|
||||
use std::net::TcpStream;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::{thread, usize};
|
||||
use std::time::Instant;
|
||||
use std::usize;
|
||||
|
||||
pub fn padding_oracle(args: &Value) -> Result<Vec<u8>> {
|
||||
let hostname: String = serde_json::from_value(args["hostname"].clone())?;
|
||||
|
|
@ -29,8 +29,6 @@ pub fn padding_oracle(args: &Value) -> Result<Vec<u8>> {
|
|||
let mut chunk_counter = 0;
|
||||
|
||||
for chunk in &cipher_chunks {
|
||||
let start = Instant::now();
|
||||
|
||||
let mut stream = TcpStream::connect(format!("{}:{}", hostname, port))?;
|
||||
stream.set_nonblocking(false)?;
|
||||
|
||||
|
|
@ -111,12 +109,12 @@ pub fn padding_oracle(args: &Value) -> Result<Vec<u8>> {
|
|||
} else {
|
||||
//eprintln!("Invalid padding");
|
||||
// Search for second hit
|
||||
let valid_val = (255
|
||||
let valid_val = 255
|
||||
- server_q_resp
|
||||
.iter()
|
||||
.rev()
|
||||
.position(|&r| r == 0x01)
|
||||
.unwrap_or(0x00) as u8);
|
||||
.unwrap_or(0x00) as u8;
|
||||
if valid_val == 0x00 {
|
||||
eprintln!("No valid found");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use crate::utils::poly::{self, polynomial_2_block};
|
||||
use crate::utils::poly::{polynomial_2_block};
|
||||
use anyhow::{Ok, Result};
|
||||
use base64::prelude::*;
|
||||
use serde_json::Value;
|
||||
|
||||
pub fn poly2block(args: &Value) -> Result<Vec<u8>> {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ pub fn sea128(args: &Value) -> Result<String> {
|
|||
let input_string: String = serde_json::from_value(args["input"].clone())?;
|
||||
//let plaintexts: &[u8] = &b64_2_num(plaintexts_string)?.to_ne_bytes();
|
||||
let input = BASE64_STANDARD.decode(input_string)?;
|
||||
let xor_val: u128 = 0xc0ffeec0ffeec0ffeec0ffeec0ffee11;
|
||||
|
||||
let mode: String = serde_json::from_value(args["mode"].clone())?;
|
||||
match mode.as_str() {
|
||||
|
|
@ -34,7 +33,6 @@ pub fn sea128(args: &Value) -> Result<String> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fs;
|
||||
|
||||
use anyhow::Result;
|
||||
use serde_json::json;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue