pub struct Decrypter { /* private fields */ }Implementations§
Source§impl Decrypter
impl Decrypter
Sourcepub fn new() -> Self
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.
Sourcepub fn set_key_from_str(&mut self, key: &str) -> Result<(), Error>
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
Error::InvalidKeyLength- if key’s length is not 32 bytes.
Sourcepub fn set_key_from_file(
&mut self,
file_content: &[u8],
file_type: FileType,
) -> Result<&str, Error>
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
Error::InvalidHeader- if passedfile_contentdata contains invalid header.Error::UnexpectedEOF- if passedfile_contentdata ends unexpectedly.
Sourcepub fn decrypt(
&mut self,
file_content: &[u8],
file_type: FileType,
) -> Result<Vec<u8>, Error>
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 passedfile_contentdata has invalid header. Vec<u8>containing decrypted data otherwise.
§Errors
Error::InvalidHeader- if passedfile_contentdata has invalid header.Error::UnexpectedEOF- if passedfile_contentdata ends unexpectedly.
Sourcepub fn decrypt_in_place<'a>(
&'a mut self,
file_content: &'a mut [u8],
file_type: FileType,
) -> Result<&'a [u8], Error>
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 passedfile_contentdata has invalid header. - Reference to a slice of the passed
file_contentdata starting at offset 16 otherwise.
§Errors
Error::InvalidHeader- if passedfile_contentdata has invalid header.Error::UnexpectedEOF- if passedfile_contentdata ends unexpectedly.
Sourcepub fn encrypt(&self, file_content: &[u8]) -> Result<Vec<u8>, Error>
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,.oggor.m4afile.
§Returns
Vec<u8>containing encrypted data if decrypter key is set.- [
Error] otherwise.
§Errors
Error::KeyNotSet- if decrypter’s key is not set.
Sourcepub fn encrypt_in_place(&self, file_content: &mut [u8]) -> Result<(), Error>
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,.oggor.m4afile.
§Returns
- Nothing, if decrypter key is set.
- [
Error] otherwise.
§Errors
Error::KeyNotSet- if decrypter’s key is not set.