[−][src]Struct internet_checksum::Checksum
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
Auto Trait Implementations
impl Send for Checksum
impl Unpin for Checksum
impl Sync for Checksum
impl UnwindSafe for Checksum
impl RefUnwindSafe for Checksum
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,