Checksum

Struct Checksum 

Source
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

Source

pub fn new(seed: u32) -> Self

Creates a new checksum from a given seed.

Source

pub fn generate_byte(&self, buffer: &[u8]) -> u8

Generates the CRC byte for the given buffer.

Source

pub fn builder(&self) -> ChecksumBuilder<'_>

Creates a ChecksumBuilder for a more fluent api.

Trait Implementations§

Source§

impl Clone for Checksum

Source§

fn clone(&self) -> Checksum

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Checksum

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Checksum

Source§

fn eq(&self, other: &Checksum) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Checksum

Source§

impl Eq for Checksum

Source§

impl StructuralPartialEq for Checksum

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V