[][src]Struct internet_checksum::Checksum

pub struct Checksum { /* fields omitted */ }

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.

Methods

impl Checksum[src]

pub const fn new() -> Self[src]

Initialize a new checksum.

pub fn add_bytes(&mut self, bytes: &[u8])[src]

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.

pub fn checksum(&self) -> [u8; 2][src]

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.

Trait Implementations

impl Default for Checksum[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]