From 7a5eda59146306dedaf3e6f07f97a8c6898543dd Mon Sep 17 00:00:00 2001 From: Frederic L Date: Tue, 30 Oct 2018 05:03:25 +0100 Subject: global: Use std::optional instead of boost::optional (#1578) * get rid of boost::optional * Remove optional references * Use std::reference_wrapper for optional references * Fix clang format * Fix clang format part 2 * Adressed feedback * Fix clang format and MacOS build --- src/core/file_sys/content_archive.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'src/core/file_sys/content_archive.cpp') diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index 77e04704e..b46fe893c 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp @@ -4,10 +4,9 @@ #include #include +#include #include -#include - #include "common/logging/log.h" #include "core/crypto/aes_util.h" #include "core/crypto/ctr_encryption_layer.h" @@ -306,18 +305,18 @@ bool NCA::ReadRomFSSection(const NCASectionHeader& section, const NCASectionTabl subsection_buckets.back().entries.push_back({section.bktr.relocation.offset, {0}, ctr_low}); subsection_buckets.back().entries.push_back({size, {0}, 0}); - boost::optional key = boost::none; + std::optional key = {}; if (encrypted) { if (has_rights_id) { status = Loader::ResultStatus::Success; key = GetTitlekey(); - if (key == boost::none) { + if (!key) { status = Loader::ResultStatus::ErrorMissingTitlekey; return false; } } else { key = GetKeyAreaKey(NCASectionCryptoType::BKTR); - if (key == boost::none) { + if (!key) { status = Loader::ResultStatus::ErrorMissingKeyAreaKey; return false; } @@ -332,7 +331,7 @@ bool NCA::ReadRomFSSection(const NCASectionHeader& section, const NCASectionTabl auto bktr = std::make_shared( bktr_base_romfs, std::make_shared(file, romfs_size, base_offset), relocation_block, relocation_buckets, subsection_block, subsection_buckets, encrypted, - encrypted ? key.get() : Core::Crypto::Key128{}, base_offset, bktr_base_ivfc_offset, + encrypted ? *key : Core::Crypto::Key128{}, base_offset, bktr_base_ivfc_offset, section.raw.section_ctr); // BKTR applies to entire IVFC, so make an offset version to level 6 @@ -388,11 +387,11 @@ u8 NCA::GetCryptoRevision() const { return master_key_id; } -boost::optional NCA::GetKeyAreaKey(NCASectionCryptoType type) const { +std::optional NCA::GetKeyAreaKey(NCASectionCryptoType type) const { const auto master_key_id = GetCryptoRevision(); if (!keys.HasKey(Core::Crypto::S128KeyType::KeyArea, master_key_id, header.key_index)) - return boost::none; + return {}; std::vector key_area(header.key_area.begin(), header.key_area.end()); Core::Crypto::AESCipher cipher( @@ -416,25 +415,25 @@ boost::optional NCA::GetKeyAreaKey(NCASectionCryptoType ty return out; } -boost::optional NCA::GetTitlekey() { +std::optional NCA::GetTitlekey() { const auto master_key_id = GetCryptoRevision(); u128 rights_id{}; memcpy(rights_id.data(), header.rights_id.data(), 16); if (rights_id == u128{}) { status = Loader::ResultStatus::ErrorInvalidRightsID; - return boost::none; + return {}; } auto titlekey = keys.GetKey(Core::Crypto::S128KeyType::Titlekey, rights_id[1], rights_id[0]); if (titlekey == Core::Crypto::Key128{}) { status = Loader::ResultStatus::ErrorMissingTitlekey; - return boost::none; + return {}; } if (!keys.HasKey(Core::Crypto::S128KeyType::Titlekek, master_key_id)) { status = Loader::ResultStatus::ErrorMissingTitlekek; - return boost::none; + return {}; } Core::Crypto::AESCipher cipher( @@ -458,25 +457,25 @@ VirtualFile NCA::Decrypt(const NCASectionHeader& s_header, VirtualFile in, u64 s case NCASectionCryptoType::BKTR: LOG_DEBUG(Crypto, "called with mode=CTR, starting_offset={:016X}", starting_offset); { - boost::optional key = boost::none; + std::optional key = {}; if (has_rights_id) { status = Loader::ResultStatus::Success; key = GetTitlekey(); - if (key == boost::none) { + if (!key) { if (status == Loader::ResultStatus::Success) status = Loader::ResultStatus::ErrorMissingTitlekey; return nullptr; } } else { key = GetKeyAreaKey(NCASectionCryptoType::CTR); - if (key == boost::none) { + if (!key) { status = Loader::ResultStatus::ErrorMissingKeyAreaKey; return nullptr; } } - auto out = std::make_shared( - std::move(in), key.value(), starting_offset); + auto out = std::make_shared(std::move(in), *key, + starting_offset); std::vector iv(16); for (u8 i = 0; i < 8; ++i) iv[i] = s_header.raw.section_ctr[0x8 - i - 1]; -- cgit v1.2.3