1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-05-01 02:47:45 +00:00

Fix size of initalization encryption packet, start testing for that

This commit is contained in:
Joshua Goins 2025-03-11 21:52:46 -04:00
parent 632342c1f0
commit 7116389afe
2 changed files with 33 additions and 1 deletions

View file

@ -38,6 +38,8 @@ async fn main() {
let n = read.read(&mut buf).await.expect("Failed to read data!");
if n != 0 {
tracing::info!("read {} bytes", n);
let (segments, _) = parse_packet(&buf[..n], &mut state).await;
for segment in &segments {
match &segment.segment_type {

View file

@ -42,11 +42,13 @@ pub enum SegmentType {
#[brw(magic = 0x9u32)]
InitializeEncryption {
#[brw(pad_before = 36)] // empty
#[br(count = 64)]
#[brw(pad_size_to = 32)]
#[br(count = 32)]
#[br(map = read_string)]
#[bw(ignore)]
phrase: String,
#[brw(pad_before = 32)]
#[brw(pad_after = 512)] // empty
key: [u8; 4],
},
@ -255,3 +257,31 @@ pub async fn send_keep_alive(
};
send_packet(socket, &[response_packet], state).await;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_packet_sizes() {
let packet_types = [SegmentType::InitializeEncryption {
phrase: String::new(),
key: [0; 4],
}];
for packet in &packet_types {
let mut cursor = Cursor::new(Vec::new());
let packet_segment = PacketSegment {
source_actor: 0,
target_actor: 0,
segment_type: packet.clone(),
};
packet_segment.write_le(&mut cursor).unwrap();
let buffer = cursor.into_inner();
assert_eq!(buffer.len(), packet_segment.calc_size() as usize);
}
}
}