Debian Codegraph @

Source/Core/DiscIO/WiiEncryptionCache.h

raw symbols SCIP
1 // Copyright 2020 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <array>
7 #include <memory>
8
9 #include "Common/CommonTypes.h"
10 #include "DiscIO/VolumeWii.h"
11
12 namespace DiscIO
13 {
14 class BlobReader;
15
16 class WiiEncryptionCache
17 {
18 public:
19 using Key = std::array<u8, VolumeWii::AES_KEY_SIZE>;
20 using HashExceptionCallback = std::function<void(
21 VolumeWii::HashBlock hash_blocks[VolumeWii::BLOCKS_PER_GROUP], u64 offset)>;
22
23 // The blob pointer is kept around for the lifetime of this object.
24 explicit WiiEncryptionCache(BlobReader* blob);
25 ~WiiEncryptionCache();
26
27 WiiEncryptionCache(WiiEncryptionCache&&) = default;
28 WiiEncryptionCache& operator=(WiiEncryptionCache&&) = default;
29
30 // It would be possible to write a custom copy constructor and assignment operator
31 // for this class, but there has been no reason to do so.
32 WiiEncryptionCache(const WiiEncryptionCache&) = delete;
33 WiiEncryptionCache& operator=(const WiiEncryptionCache&) = delete;
34
35 // Encrypts exactly one group.
36 // If the returned pointer is nullptr, reading from the blob failed.
37 // If the returned pointer is not nullptr, it is guaranteed to be valid until
38 // the next call of this function or the destruction of this object.
39 const std::array<u8, VolumeWii::GROUP_TOTAL_SIZE>*
40 EncryptGroup(u64 offset, u64 partition_data_offset, u64 partition_data_decrypted_size,
41 const Key& key, const HashExceptionCallback& hash_exception_callback = {});
42
43 // Encrypts a variable number of groups, as determined by the offset and size parameters.
44 // Supports reading groups partially.
45 bool EncryptGroups(u64 offset, u64 size, u8* out_ptr, u64 partition_data_offset,
46 u64 partition_data_decrypted_size, const Key& key,
47 const HashExceptionCallback& hash_exception_callback = {});
48
49 private:
50 BlobReader* m_blob;
51 std::unique_ptr<std::array<u8, VolumeWii::GROUP_TOTAL_SIZE>> m_cache;
52 u64 m_cached_offset = 0;
53 };
54
55 } // namespace DiscIO