diff options
| author | bunnei <bunneidev@gmail.com> | 2018-09-20 10:13:10 -0400 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-09-20 10:13:10 -0400 | 
| commit | b02a1e38fa14613122c69bc4e708785d28416ea7 (patch) | |
| tree | 46be6c81a0dbec6578cb4a11c13e2f5c1acd2632 /src/core | |
| parent | e57aa62b11ccf8188c8b5d1778f83797b27565dd (diff) | |
| parent | 2e5f0e5024fac21808de12fd9008feb85dc2f02c (diff) | |
Merge pull request #1361 from lioncash/nax
xts_archive/nax: Minor interface changes
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/file_sys/xts_archive.cpp | 11 | ||||
| -rw-r--r-- | src/core/file_sys/xts_archive.h | 4 | ||||
| -rw-r--r-- | src/core/loader/nax.cpp | 26 | ||||
| -rw-r--r-- | src/core/loader/nax.h | 4 | 
4 files changed, 26 insertions, 19 deletions
| diff --git a/src/core/file_sys/xts_archive.cpp b/src/core/file_sys/xts_archive.cpp index 0173f71c1..e937d1403 100644 --- a/src/core/file_sys/xts_archive.cpp +++ b/src/core/file_sys/xts_archive.cpp @@ -30,9 +30,6 @@ static bool CalculateHMAC256(Destination* out, const SourceKey* key, std::size_t      mbedtls_md_context_t context;      mbedtls_md_init(&context); -    const auto key_f = reinterpret_cast<const u8*>(key); -    const std::vector<u8> key_v(key_f, key_f + key_length); -      if (mbedtls_md_setup(&context, mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), 1) ||          mbedtls_md_hmac_starts(&context, reinterpret_cast<const u8*>(key), key_length) ||          mbedtls_md_hmac_update(&context, reinterpret_cast<const u8*>(data), data_length) || @@ -45,7 +42,7 @@ static bool CalculateHMAC256(Destination* out, const SourceKey* key, std::size_t      return true;  } -NAX::NAX(VirtualFile file_) : file(std::move(file_)), header(std::make_unique<NAXHeader>()) { +NAX::NAX(VirtualFile file_) : header(std::make_unique<NAXHeader>()), file(std::move(file_)) {      std::string path = FileUtil::SanitizePath(file->GetFullPath());      static const std::regex nax_path_regex("/registered/(000000[0-9A-F]{2})/([0-9A-F]{32})\\.nca",                                             std::regex_constants::ECMAScript | @@ -65,7 +62,7 @@ NAX::NAX(VirtualFile file_) : file(std::move(file_)), header(std::make_unique<NA  }  NAX::NAX(VirtualFile file_, std::array<u8, 0x10> nca_id) -    : file(std::move(file_)), header(std::make_unique<NAXHeader>()) { +    : header(std::make_unique<NAXHeader>()), file(std::move(file_)) {      Core::Crypto::SHA256Hash hash{};      mbedtls_sha256(nca_id.data(), nca_id.size(), hash.data(), 0);      status = Parse(fmt::format("/registered/000000{:02X}/{}.nca", hash[0], @@ -138,9 +135,9 @@ VirtualFile NAX::GetDecrypted() const {      return dec_file;  } -std::shared_ptr<NCA> NAX::AsNCA() const { +std::unique_ptr<NCA> NAX::AsNCA() const {      if (type == NAXContentType::NCA) -        return std::make_shared<NCA>(GetDecrypted()); +        return std::make_unique<NCA>(GetDecrypted());      return nullptr;  } diff --git a/src/core/file_sys/xts_archive.h b/src/core/file_sys/xts_archive.h index 55d2154a6..6e2fc4d2e 100644 --- a/src/core/file_sys/xts_archive.h +++ b/src/core/file_sys/xts_archive.h @@ -38,7 +38,7 @@ public:      VirtualFile GetDecrypted() const; -    std::shared_ptr<NCA> AsNCA() const; +    std::unique_ptr<NCA> AsNCA() const;      NAXContentType GetContentType() const; @@ -60,7 +60,7 @@ private:      VirtualFile file;      Loader::ResultStatus status; -    NAXContentType type; +    NAXContentType type{};      VirtualFile dec_file; diff --git a/src/core/loader/nax.cpp b/src/core/loader/nax.cpp index b46d81c02..5d4380684 100644 --- a/src/core/loader/nax.cpp +++ b/src/core/loader/nax.cpp @@ -11,6 +11,20 @@  #include "core/loader/nca.h"  namespace Loader { +namespace { +FileType IdentifyTypeImpl(const FileSys::NAX& nax) { +    if (nax.GetStatus() != ResultStatus::Success) { +        return FileType::Error; +    } + +    const auto nca = nax.AsNCA(); +    if (nca == nullptr || nca->GetStatus() != ResultStatus::Success) { +        return FileType::Error; +    } + +    return FileType::NAX; +} +} // Anonymous namespace  AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file)      : AppLoader(file), nax(std::make_unique<FileSys::NAX>(file)), @@ -19,14 +33,12 @@ AppLoader_NAX::AppLoader_NAX(FileSys::VirtualFile file)  AppLoader_NAX::~AppLoader_NAX() = default;  FileType AppLoader_NAX::IdentifyType(const FileSys::VirtualFile& file) { -    FileSys::NAX nax(file); - -    if (nax.GetStatus() == ResultStatus::Success && nax.AsNCA() != nullptr && -        nax.AsNCA()->GetStatus() == ResultStatus::Success) { -        return FileType::NAX; -    } +    const FileSys::NAX nax(file); +    return IdentifyTypeImpl(nax); +} -    return FileType::Error; +FileType AppLoader_NAX::GetFileType() { +    return IdentifyTypeImpl(*nax);  }  ResultStatus AppLoader_NAX::Load(Kernel::SharedPtr<Kernel::Process>& process) { diff --git a/src/core/loader/nax.h b/src/core/loader/nax.h index 4dbae2918..56605fe45 100644 --- a/src/core/loader/nax.h +++ b/src/core/loader/nax.h @@ -31,9 +31,7 @@ public:       */      static FileType IdentifyType(const FileSys::VirtualFile& file); -    FileType GetFileType() override { -        return IdentifyType(file); -    } +    FileType GetFileType() override;      ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; | 
