Add password support for archive reader
This commit is contained in:
@@ -18,6 +18,12 @@ namespace OpenVulkano
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
constexpr int BUFFER_SIZE = 16384;
|
constexpr int BUFFER_SIZE = 16384;
|
||||||
|
|
||||||
|
const char* ArchivePasswordCallbackHandler(struct archive *, void *_client_data)
|
||||||
|
{
|
||||||
|
ArchiveReader* reader = static_cast<ArchiveReader*>(_client_data);
|
||||||
|
return reader->GetPasswordCallback()();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchiveReader::ArchiveReader(const std::shared_ptr<spdlog::logger>& logger, std::optional<ArchiveType::Type> archiveType)
|
ArchiveReader::ArchiveReader(const std::shared_ptr<spdlog::logger>& logger, std::optional<ArchiveType::Type> archiveType)
|
||||||
@@ -42,6 +48,11 @@ namespace OpenVulkano
|
|||||||
|
|
||||||
ArchiveReader::~ArchiveReader() = default;
|
ArchiveReader::~ArchiveReader() = default;
|
||||||
|
|
||||||
|
void ArchiveReader::SetPasswordCallback(const decltype(m_passwordCallback)& callback)
|
||||||
|
{
|
||||||
|
archive_read_set_passphrase_callback(m_archive, this, &ArchivePasswordCallbackHandler);
|
||||||
|
}
|
||||||
|
|
||||||
void ArchiveReader::PrepOpen()
|
void ArchiveReader::PrepOpen()
|
||||||
{
|
{
|
||||||
if (m_open)
|
if (m_open)
|
||||||
|
|||||||
@@ -19,10 +19,11 @@ namespace OpenVulkano
|
|||||||
{
|
{
|
||||||
class ArchiveReader final : public ArchiveBase
|
class ArchiveReader final : public ArchiveBase
|
||||||
{
|
{
|
||||||
bool m_open = false;
|
|
||||||
bool m_eof = false;
|
|
||||||
std::optional<ArchiveType::Type> m_archiveType;
|
std::optional<ArchiveType::Type> m_archiveType;
|
||||||
std::queue<std::string> m_archivesToRead;
|
std::queue<std::string> m_archivesToRead;
|
||||||
|
std::function<const char*()> m_passwordCallback;
|
||||||
|
bool m_open = false;
|
||||||
|
bool m_eof = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ArchiveReader(const std::shared_ptr<spdlog::logger>& logger = nullptr, std::optional<ArchiveType::Type> archiveType = std::nullopt);
|
explicit ArchiveReader(const std::shared_ptr<spdlog::logger>& logger = nullptr, std::optional<ArchiveType::Type> archiveType = std::nullopt);
|
||||||
@@ -35,6 +36,8 @@ namespace OpenVulkano
|
|||||||
|
|
||||||
~ArchiveReader() override;
|
~ArchiveReader() override;
|
||||||
|
|
||||||
|
void SetPasswordCallback(const decltype(m_passwordCallback)& callback);
|
||||||
|
|
||||||
bool Open(const char* archiveFile);
|
bool Open(const char* archiveFile);
|
||||||
|
|
||||||
bool Open(const std::string& archiveFile);
|
bool Open(const std::string& archiveFile);
|
||||||
@@ -72,6 +75,8 @@ namespace OpenVulkano
|
|||||||
|
|
||||||
bool GetNextFileAsStream(const std::function<void(const FileDescription&, std::istream&)>& streamReader);
|
bool GetNextFileAsStream(const std::function<void(const FileDescription&, std::istream&)>& streamReader);
|
||||||
|
|
||||||
|
const decltype(m_passwordCallback)& GetPasswordCallback() const { return m_passwordCallback; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ReadNextHeader();
|
void ReadNextHeader();
|
||||||
std::function<int(archive*)> GetCurrentFormatReadFunc() const;
|
std::function<int(archive*)> GetCurrentFormatReadFunc() const;
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ namespace OpenVulkano
|
|||||||
if (buffer.first == nullptr) continue;
|
if (buffer.first == nullptr) continue;
|
||||||
size += buffer.second;
|
size += buffer.second;
|
||||||
}
|
}
|
||||||
FileDescription description = FileDescription::MakeDescriptionForFile(fileName, size);
|
const FileDescription description = FileDescription::MakeDescriptionForFile(fileName, size);
|
||||||
return AddFile(description, buffers);
|
return AddFile(description, buffers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user