Function internet_checksum::update

source ·
pub fn update(checksum: [u8; 2], old: &[u8], new: &[u8]) -> [u8; 2]
Expand description

Updates bytes in an existing checksum.

update updates a checksum to reflect that the already-checksummed bytes old have been updated to contain the values in new. It implements the algorithm described in Equation 3 in RFC 1624. The first byte must be at an even number offset in the original input. If an odd number offset byte needs to be updated, the caller should simply include the preceding byte as well. If an odd number of bytes is given, it is assumed that these are the last bytes of the input. If an odd number of bytes in the middle of the input needs to be updated, the preceding or following byte of the input should be added to make an even number of bytes.

§Panics

update panics if old.len() != new.len().