fix: parsing
This commit is contained in:
		
							parent
							
								
									913ae5e74a
								
							
						
					
					
						commit
						3eece7ecd9
					
				
					 5 changed files with 105 additions and 104 deletions
				
			
		|  | @ -9,13 +9,14 @@ impl TryFrom<Vec<u8>> for RawPacket { | |||
|         if data.len() < PACKET_HEADER_SIZE { | ||||
|             return Err(io::Error::new(io::ErrorKind::InvalidData, "Can't parse data into RawPacket")) | ||||
|         } | ||||
|         let data_length = u16::from_be_bytes([data[0x12], data[0x13]]) as usize; | ||||
|         if data.len() < 0x14 + data_length + 4 { | ||||
|         let data_length = (((data[0x12] as u16) << 8) | data[0x13] as u16) as usize; | ||||
|         if data.len() < 0x14 + data_length { | ||||
|             return Err(io::Error::new(io::ErrorKind::InvalidData, "Can't parse data into RawPacket")) | ||||
|         } | ||||
|         let checksum = as_u32_be(data[(data.len() - 5)..].as_ref()); | ||||
|         if checksum != crc32fast::hash(data[..(data.len() - 4)].as_ref()) { | ||||
|             return Err(io::Error::new(io::ErrorKind::InvalidData, "Checksum does not match")) | ||||
|         let checksum = as_u32_be(data[(data.len() - 4)..].as_ref()); | ||||
|         let built_checksum = crc32fast::hash(data[..(data.len() - 4)].as_ref()); | ||||
|         if checksum != built_checksum { | ||||
|             return Err(io::Error::new(io::ErrorKind::InvalidData, format!("Checksum does not match {checksum:X?} != {built_checksum:X?}"))) | ||||
|         } | ||||
|         Ok(RawPacket { | ||||
|             version: data[0], | ||||
|  | @ -25,7 +26,7 @@ impl TryFrom<Vec<u8>> for RawPacket { | |||
|             reply_to: as_u32_be(data[0x0D..0x11].as_ref()), | ||||
|             command: data[0x11], | ||||
|             data_length, | ||||
|             data: data[0x14..data_length].to_vec(), | ||||
|             data: data[0x14..(0x14 + data_length)].to_vec(), | ||||
|             checksum, | ||||
|         }) | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue