Decrypter

Struct Decrypter 

Source
pub struct Decrypter { /* private fields */ }

Implementations§

Source§

impl Decrypter

Source

pub fn new() -> Self

Creates a new Decrypter instance.

Decrypter requires a key, which you can set from Decrypter::set_key_from_str and Decrypter::set_key_from_file functions. You can get the key string from encryptionKey field in System.json file or from any encrypted RPG Maker file.

Decrypter::decrypt function will automatically determine the key from the input file, so you usually don’t need to set it manually.

Source

pub fn key(&self) -> Option<&str>

Returns the decrypter’s key, or None if it’s not set.

Source

pub fn set_key_from_str(&mut self, key: &str) -> Result<(), Error>

Sets the decrypter’s key to provided &str hex string.

§Returns

If key’s length is not 32 bytes, the function fails and returns [Error].

§Errors
Source

pub fn set_key_from_file( &mut self, file_content: &[u8], file_type: FileType, ) -> Result<&str, Error>

Sets the key of decrypter from encrypted file_content data.

§Arguments
  • file_content - The data of RPG Maker file.
§Returns
  • Reference to the key string, if succeeded.
  • [Error] otherwise.
§Errors
Source

pub fn decrypt( &mut self, file_content: &[u8], file_type: FileType, ) -> Result<Vec<u8>, Error>

Decrypts RPG Maker file content. Auto-determines the key from the input file.

This function copies the contents of the file and returns decrypted Vec<u8> copy. If you want to avoid copying, see Decrypter::decrypt_in_place function.

§Arguments
  • file_content - The data of RPG Maker file.
  • file_type - FileType, representing whether passed file content is PNG, OGG or M4A.
§Returns
  • [Error], if passed file_content data has invalid header.
  • Vec<u8> containing decrypted data otherwise.
§Errors
Source

pub fn decrypt_in_place<'a>( &'a mut self, file_content: &'a mut [u8], file_type: FileType, ) -> Result<&'a [u8], Error>

Decrypts RPG Maker file content. Auto-determines the key from the input file.

This function decrypts the passed file data in-place. If you don’t want to modify passed data, see Decrypter::decrypt function.

§Note

Decrypted data is only valid starting at offset 16. This function returns the reference to the correct slice.

§Arguments
  • file_content - The data of RPG Maker file.
  • file_type - FileType, representing whether passed file content is PNG, OGG or M4A.
§Returns
  • [Error], if passed file_content data has invalid header.
  • Reference to a slice of the passed file_content data starting at offset 16 otherwise.
§Errors
Source

pub fn encrypt(&self, file_content: &[u8]) -> Result<Vec<u8>, Error>

Encrypts file content.

This function requires decrypter to have a key, which you can fetch from System.json file or by calling Decrypter::set_key_from_file with the data from encrypted file.

This function copies the contents of the file and returns encrypted Vec<u8> copy. If you want to avoid copying, see Decrypter::encrypt_in_place function.

§Arguments
  • file_content - The data of .png, .ogg or .m4a file.
§Returns
  • Vec<u8> containing encrypted data if decrypter key is set.
  • [Error] otherwise.
§Errors
Source

pub fn encrypt_in_place(&self, file_content: &mut [u8]) -> Result<(), Error>

Encrypts file content in-place.

This function requires decrypter to have a key, which you can fetch from System.json file or by calling Decrypter::set_key_from_file with the data from encrypted file.

This function encrypts the passed file data in-place. If you don’t want to modify passed data, see Decrypter::encrypt function.

§Note

Encrypted data comes without the RPG Maker header, so you need to manually prepend it - but you can decide where and how to do it most efficient. The header is exported as RPGM_HEADER.

§Arguments
  • file_content - The data of .png, .ogg or .m4a file.
§Returns
  • Nothing, if decrypter key is set.
  • [Error] otherwise.
§Errors

Trait Implementations§

Source§

impl Default for Decrypter

Source§

fn default() -> Decrypter

Returns the “default value” for a type. Read more

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