core: Add DecryptToFile in NCCHContainer

This commit is contained in:
zhupengfei
2020-05-01 11:59:24 +08:00
parent e4c3588aa1
commit c27589ce53
5 changed files with 170 additions and 25 deletions
+18 -5
View File
@@ -33,11 +33,23 @@ public:
explicit QuickDecryptor();
~QuickDecryptor();
bool DecryptAndWriteFile(std::unique_ptr<In> source, std::size_t size,
std::unique_ptr<Out> destination,
/**
* Decrypts and writes a file.
*
* @param source Source file
* @param size Size to read, decrypt and write
* @param destination Destination file
* @param callback Progress callback
* @param decrypt Whether to perform decryption or not
* @param key AES Key for decryption
* @param ctr AES CTR for decryption
* @param aes_seek_pos The position to seek to for decryption.
*/
bool DecryptAndWriteFile(std::shared_ptr<In> source, std::size_t size,
std::shared_ptr<Out> destination,
const ProgressCallback& callback = [](std::size_t, std::size_t) {},
bool decrypt = false, Core::Key::AESKey key = {},
Core::Key::AESKey ctr = {});
Core::Key::AESKey ctr = {}, std::size_t aes_seek_pos = 0);
void DataReadLoop();
void DataDecryptLoop();
@@ -51,11 +63,12 @@ public:
private:
static constexpr std::size_t BufferSize = 16 * 1024; // 16 KB
std::unique_ptr<In> source;
std::unique_ptr<Out> destination;
std::shared_ptr<In> source;
std::shared_ptr<Out> destination;
bool decrypt{};
Core::Key::AESKey key;
Core::Key::AESKey ctr;
std::size_t aes_seek_pos;
// Total size of this content, may consist of multiple files
std::size_t total_size{};