fs: add Sha256HashGenerator, LZ4 decompressor

This commit is contained in:
Michael Scire 2021-12-14 08:51:27 -08:00 committed by SciresM
parent a2aec363d7
commit 01f7f567b9
11 changed files with 165 additions and 8 deletions

View file

@ -48,4 +48,5 @@
#include <stratosphere/fssystem/save/fssystem_buffered_storage.hpp>
#include <stratosphere/fssystem/save/fssystem_hierarchical_integrity_verification_storage.hpp>
#include <stratosphere/fssystem/fssystem_integrity_romfs_storage.hpp>
#include <stratosphere/fssystem/fssystem_sha256_hash_generator.hpp>
#include <stratosphere/fssystem/fssystem_file_system_proxy_api.hpp>

View file

@ -66,6 +66,7 @@ namespace ams::fssystem {
public:
virtual Result QueryAppropriateOffset(s64 *out, s64 offset, s64 access_size, s64 alignment_size) override {
AMS_ABORT("TODO");
AMS_UNUSED(out, offset, access_size, alignment_size);
/* return m_core.QueryAppropriateOffsetForAsynchronousAccess(out, offset, access_size, alignment_size); */
}
public:
@ -74,6 +75,7 @@ namespace ams::fssystem {
virtual Result GetSize(s64 *out) override {
AMS_ABORT("TODO");
AMS_UNUSED(out);
/* return m_core.GetSize(out); */
}

View file

@ -40,7 +40,7 @@ namespace ams::fssystem {
}
constexpr bool IsRandomAccessible(CompressionType type) {
return CompressionType_None;
return type == CompressionType_None;
}
constexpr bool IsUnknownType(CompressionType type) {

View file

@ -0,0 +1,71 @@
/*
* Copyright (c) Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <vapours.hpp>
#include <stratosphere/fssystem/fssystem_i_hash_256_generator.hpp>
namespace ams::fssystem {
class Sha256HashGenerator final : public ::ams::fssystem::IHash256Generator, public ::ams::fs::impl::Newable {
NON_COPYABLE(Sha256HashGenerator);
NON_MOVEABLE(Sha256HashGenerator);
private:
crypto::Sha256Generator m_generator;
public:
Sha256HashGenerator() = default;
protected:
virtual void DoInitialize() override {
m_generator.Initialize();
}
virtual void DoUpdate(const void *data, size_t size) override {
m_generator.Update(data, size);
}
virtual void DoGetHash(void *dst, size_t dst_size) override {
m_generator.GetHash(dst, dst_size);
}
};
class Sha256HashGeneratorFactory final : public IHash256GeneratorFactory, public ::ams::fs::impl::Newable {
NON_COPYABLE(Sha256HashGeneratorFactory);
NON_MOVEABLE(Sha256HashGeneratorFactory);
public:
Sha256HashGeneratorFactory() = default;
protected:
virtual std::unique_ptr<IHash256Generator> DoCreate() override {
return std::unique_ptr<IHash256Generator>(new Sha256HashGenerator());
}
virtual void DoGenerateHash(void *dst, size_t dst_size, const void *src, size_t src_size) override {
crypto::GenerateSha256Hash(dst, dst_size, src, src_size);
}
};
class Sha256HashGeneratorFactorySelector final : public IHash256GeneratorFactorySelector, public ::ams::fs::impl::Newable {
NON_COPYABLE(Sha256HashGeneratorFactorySelector);
NON_MOVEABLE(Sha256HashGeneratorFactorySelector);
private:
Sha256HashGeneratorFactory m_factory;
public:
Sha256HashGeneratorFactorySelector() = default;
protected:
virtual IHash256GeneratorFactory *DoGetFactory() override {
return std::addressof(m_factory);
}
};
}

View file

@ -82,7 +82,7 @@ namespace ams::fssystem::save {
void CalcBlockHash(BlockHash *out, const void *buffer, size_t block_size, std::unique_ptr<fssystem::IHash256Generator> &generator) const;
void CalcBlockHash(BlockHash *out, const void *buffer, std::unique_ptr<fssystem::IHash256Generator> &generator) const {
return this->CalcBlockHash(out, buffer, static_cast<size_t>(m_verification_block_size));
return this->CalcBlockHash(out, buffer, static_cast<size_t>(m_verification_block_size), generator);
}
Result IsCleared(bool *is_cleared, const BlockHash &hash);