add WIP extra packet validation

This commit is contained in:
Mystikfluu
2023-05-30 22:12:23 +02:00
parent c1e4b3cd7a
commit bd118b3164
4 changed files with 56 additions and 8 deletions
+1 -2
View File
@@ -63,6 +63,5 @@ macro_rules! big_array {
}
big_array! {
40, 48, 50, 56, 64, 72, 96, 100, 128, 160, 192, 200, 224, 256, 384, 488, 500, 512,
768, 1024, 2048, 4096, 8192, 16384, 32768, 65536,
496, 500, 512,
}
+14 -1
View File
@@ -10,7 +10,7 @@ use big_array::BigArray;
const MAX_FRAME_PAYLOAD:u16=508;
const MAX_FRAME_PAYLOAD_U:usize=MAX_FRAME_PAYLOAD as usize;
const HEADER_SIZE:u16 = 8;
const HEADER_SIZE:u16 = 12;
const MAX_PAYLOAD:u16 = MAX_FRAME_PAYLOAD - HEADER_SIZE;
const MAX_PAYLOAD_U:usize = MAX_PAYLOAD as usize;
@@ -25,6 +25,7 @@ struct PacketInformation {
struct Packet {
packet_number: u32, //4 bytes
payload_hash: [u8; 4], //4 bytes
payload_sum_hash: u32, //4 bytes
#[serde(with = "BigArray")]
payload: [u8; MAX_PAYLOAD_U],
} //508 bytes
@@ -107,8 +108,10 @@ fn main() {
//create vector to store the packets
let mut packets: Vec<Vec<u8>> = Vec::new();
let mut packet_hashes: Vec<u32> = Vec::new();
for _ in 0..packet_info.packet_numbers {
packets.push(Vec::new());
packet_hashes.push(0);
}
let mut received_packets = 0;
@@ -155,6 +158,7 @@ fn main() {
if p.payload_hash != hash.to_be_bytes() {
continue;
}
packet_hashes[p.packet_number as usize] = p.payload_sum_hash;
packet = p;
} else {
@@ -217,6 +221,15 @@ fn main() {
print!("Packet {}/{}\r", received_packets, packet_info.packet_numbers);
}
let mut crc32 = crc32fast::Hasher::new();
for i in 0..packets.len() {
crc32.update(&packets[i]);
if packet_hashes[i] != crc32.clone().finalize() {
println!("Packet {} hash does not match", i);
todo!("Request packets again")
}
}
//check hash via sha512
let mut hasher = Sha512::new();