pub struct Checksum { /* private fields */ }Expand description
Generates a CRC checksum according to the algorithm used in Silkroad Online.
Just like a hash, given the same input (seed & data), it will produce the same output. The seed is expected to be generated randomly and exchanged prior. Then the output can be used to ensure no accidental changes have been made to the data.
let checksum = Checksum::new(random::<u32>());
let crc = checksum.generate_byte(&[0x01, 0x02]);While the seed is considered a u32, only the lower 8 bits are actually used; any other will
be discarded. Technically, it would be more correct for this seed to accept a u8 instead to
ensure this on a type level. However, we’re keeping it as a u32 because inside the silkroad
packets the seed occupies a u32. We want to keep this in sync. For now, the following is thus
correct:
let checksum = Checksum::new(10 + 256);
let checksum2 = Checksum::new(10);
assert_eq!(checksum, checksum2);Implementations§
Source§impl Checksum
impl Checksum
Sourcepub fn generate_byte(&self, buffer: &[u8]) -> u8
pub fn generate_byte(&self, buffer: &[u8]) -> u8
Generates the CRC byte for the given buffer.
Sourcepub fn builder(&self) -> ChecksumBuilder<'_>
pub fn builder(&self) -> ChecksumBuilder<'_>
Creates a ChecksumBuilder for a more fluent api.