pub struct Checksum { /* private fields */ }
Expand description
RFC 1071 “internet checksum” computation.
Checksum
implements the “internet checksum” defined in RFC 1071 and
updated in RFC 1141 and RFC 1624, which is used by many different
protocols’ packet formats. The checksum operates by computing the 1s
complement of the 1s complement sum of successive 16-bit words of the input.
Implementations§
Source§impl Checksum
impl Checksum
Sourcepub fn add_bytes(&mut self, bytes: &[u8])
pub fn add_bytes(&mut self, bytes: &[u8])
Add bytes to the checksum.
If bytes
does not contain an even number of bytes, a single zero byte
will be added to the end before updating the checksum.
Note that add_bytes
has some fixed overhead regardless of the size of
bytes
. Where performance is a concern, prefer fewer calls to
add_bytes
with larger input over more calls with smaller input.
Sourcepub fn checksum(&self) -> [u8; 2]
pub fn checksum(&self) -> [u8; 2]
Computes the checksum, and returns the array representation.
checksum
returns the checksum of all data added using add_bytes
so
far. Calling checksum
does not reset the checksum. More bytes may be
added after calling checksum
, and they will be added to the checksum
as expected.
If an odd number of bytes have been added so far, the checksum will be computed as though a single 0 byte had been added at the end in order to even out the length of the input.