yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

partition_data_manager: Dehardcode array bounds

Instead, we can make it part of the type and make named variables for
them, so they only require one definition (and if they ever change for
whatever reason, they only need to be changed in one spot).
This commit is contained in:
Lioncash 2018-10-13 08:52:34 -04:00
parent d257a3b56c
commit f56a8da46a
2 changed files with 12 additions and 7 deletions

View File

@ -332,18 +332,18 @@ FileSys::VirtualFile PartitionDataManager::GetBoot0Raw() const {
return boot0; return boot0;
} }
std::array<u8, 176> PartitionDataManager::GetEncryptedKeyblob(u8 index) const { PartitionDataManager::EncryptedKeyBlob PartitionDataManager::GetEncryptedKeyblob(u8 index) const {
if (HasBoot0() && index < 32) if (HasBoot0() && index < NUM_ENCRYPTED_KEYBLOBS)
return GetEncryptedKeyblobs()[index]; return GetEncryptedKeyblobs()[index];
return {}; return {};
} }
std::array<std::array<u8, 176>, 32> PartitionDataManager::GetEncryptedKeyblobs() const { PartitionDataManager::EncryptedKeyBlobs PartitionDataManager::GetEncryptedKeyblobs() const {
if (!HasBoot0()) if (!HasBoot0())
return {}; return {};
std::array<std::array<u8, 176>, 32> out{}; EncryptedKeyBlobs out{};
for (size_t i = 0; i < 0x20; ++i) for (size_t i = 0; i < out.size(); ++i)
boot0->Read(out[i].data(), out[i].size(), 0x180000 + i * 0x200); boot0->Read(out[i].data(), out[i].size(), 0x180000 + i * 0x200);
return out; return out;
} }

View File

@ -22,6 +22,11 @@ enum class Package2Type {
class PartitionDataManager { class PartitionDataManager {
public: public:
static const u8 MAX_KEYBLOB_SOURCE_HASH; static const u8 MAX_KEYBLOB_SOURCE_HASH;
static constexpr std::size_t NUM_ENCRYPTED_KEYBLOBS = 32;
static constexpr std::size_t ENCRYPTED_KEYBLOB_SIZE = 0xB0;
using EncryptedKeyBlob = std::array<u8, ENCRYPTED_KEYBLOB_SIZE>;
using EncryptedKeyBlobs = std::array<EncryptedKeyBlob, NUM_ENCRYPTED_KEYBLOBS>;
explicit PartitionDataManager(const FileSys::VirtualDir& sysdata_dir); explicit PartitionDataManager(const FileSys::VirtualDir& sysdata_dir);
~PartitionDataManager(); ~PartitionDataManager();
@ -29,8 +34,8 @@ public:
// BOOT0 // BOOT0
bool HasBoot0() const; bool HasBoot0() const;
FileSys::VirtualFile GetBoot0Raw() const; FileSys::VirtualFile GetBoot0Raw() const;
std::array<u8, 0xB0> GetEncryptedKeyblob(u8 index) const; EncryptedKeyBlob GetEncryptedKeyblob(u8 index) const;
std::array<std::array<u8, 0xB0>, 0x20> GetEncryptedKeyblobs() const; EncryptedKeyBlobs GetEncryptedKeyblobs() const;
std::vector<u8> GetSecureMonitor() const; std::vector<u8> GetSecureMonitor() const;
std::array<u8, 0x10> GetPackage2KeySource() const; std::array<u8, 0x10> GetPackage2KeySource() const;
std::array<u8, 0x10> GetAESKekGenerationSource() const; std::array<u8, 0x10> GetAESKekGenerationSource() const;