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
impl SilkroadEncryption
Sourcepub fn decrypt(&self, data: &[u8]) -> Result<Bytes, SilkroadSecurityError>
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.
Sourcepub fn decrypt_mut(&self, data: &mut [u8]) -> Result<(), SilkroadSecurityError>
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.
Sourcepub fn encrypt(&self, data: &[u8]) -> Result<Bytes, SilkroadSecurityError>
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.
Sourcepub fn encrypt_mut(&self, data: &mut [u8]) -> Result<(), SilkroadSecurityError>
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
Sourcepub fn find_encrypted_length(given_length: usize) -> usize
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.