Struct SilkroadEncryption

Source
pub struct SilkroadEncryption { /* private fields */ }
Expand description

Handles the encryption/decryption of data in Silkroad Online.

Generally only the client encrypts data, but this is a generic encryption setup. This is essentially a thin veil around [BlowfishCompat], only ensuring the right block size has been used.

You can create this with a predefined key:

let encryption = SilkroadEncryption::from_key(0xFF00FF00FF00FF00);

Though generally the security should be set up through a handshake.

Implementations§

Source§

impl SilkroadEncryption

Source

pub fn from_key(key: u64) -> Self

Creates an encryption setup from a predefined key.

Source

pub fn decrypt(&self, data: &[u8]) -> Result<Bytes, SilkroadSecurityError>

Decrypt an encrypted message sent by the client.

Decrypts the given input by splitting it into the individual encrypted blocks. The output is all decrypted data, which may contain padding that was added before encryption. Bytes are copied before performing decryption. To decrypt in place, use decrypt_mut.

If the input doesn’t match the required block length it will return SilkroadSecurityError::InvalidBlockLength.

Source

pub fn decrypt_mut(&self, data: &mut [u8]) -> Result<(), SilkroadSecurityError>

Decrypt an encrypted message sent by the client.

Decrypts the given input by splitting it into the individual encrypted blocks in place. The decrypted data may still be padded to match block length (8 bytes).

If the input doesn’t match the required block length it will return SilkroadSecurityError::InvalidBlockLength.

Source

pub fn encrypt(&self, data: &[u8]) -> Result<Bytes, SilkroadSecurityError>

Encrypt a message to be sent to the client.

Encrypts the given bytes using the previously established secret. Requires that the handshake has been completed. It will copy the bytes and return the encrypted bytes as an owned reference. Bytes will be padded automatically to the necessary block length. Use encrypt_mut for encryption in place.

Source

pub fn encrypt_mut(&self, data: &mut [u8]) -> Result<(), SilkroadSecurityError>

Encrypt a message to be sent to the client.

Encrypts the given bytes using the previously established secret. Requires that the handshake has been completed and that data is a multiple of the block length.

If the data is not block-aligned, will result in SilkroadSecurityError::InvalidBlockLength

Source

pub fn find_encrypted_length(given_length: usize) -> usize

Find the nearest block-aligned length.

Given the current length of data to encrypt, calculates the length of the encrypted output, which includes padding. Can at most increase by BLOWFISH_BLOCK_SIZE - 1, which is 7.

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> 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, 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