28 explicit Error(
const std::string& description);
92 auto operator*() const -> const
Entry&
114 return (m_is ==
nullptr) == (other.m_is ==
nullptr);
120 return !(*
this == other);
124 std::istream* m_is =
nullptr;
125 std::optional<Entry> m_entry;
130 explicit Zip(std::istream& stream);
135 explicit Zip(
const std::string& filename);
167 auto load(
const Entry& entry, std::size_t count = std::numeric_limits<std::size_t>::max()) const
168 -> std::vector<std::uint8_t>;
179 std::optional<std::ifstream> m_file;
181 const std::uint64_t m_centralDirectoryOffset;
186void decipher(std::istream& is, std::
size_t size, std::
size_t discard, std::ostream& os,
Keys keys);
BaseError(const std::string &type, const std::string &description)
Constructor.
Keys defining the cipher state.
Definition Keys.hpp:10
Structure to report the progress of a long operation or to cancel it.
Definition Progress.hpp:10
Error(const std::string &description)
Constructor.
Single-pass input iterator that reads successive Entry objects.
Definition Zip.hpp:72
auto operator->() const -> const Entry *
Access a member of the current entry.
Definition Zip.hpp:99
std::ptrdiff_t difference_type
Required types for iterators.
Definition Zip.hpp:76
const Entry value_type
Required types for iterators.
Definition Zip.hpp:77
std::input_iterator_tag iterator_category
Required types for iterators.
Definition Zip.hpp:80
auto operator++() -> Iterator &
Read the next central directory record if any or assign end-of-stream iterator.
const Entry & reference
Required types for iterators.
Definition Zip.hpp:79
constexpr Iterator() noexcept=default
Construct end-of-stream iterator.
auto operator++(int) -> Iterator
Read the next central directory record if any or assign end-of-stream iterator.
auto operator==(const Zip::Iterator &other) const -> bool
Test if iterators are equivalent, i.e. both are end-of-stream or both are valid.
Definition Zip.hpp:112
auto operator!=(const Zip::Iterator &other) const -> bool
Test if iterators are not equivalent.
Definition Zip.hpp:118
const Entry * pointer
Required types for iterators.
Definition Zip.hpp:78
auto begin() const -> Iterator
Get an iterator pointing to the first entry.
Definition Zip.hpp:138
auto operator[](const std::string &name) const -> Entry
Get the first entry having the given name.
Compression
Compression algorithm.
Definition Zip.hpp:41
static void checkEncryption(const Entry &entry, Encryption expected)
Check that the given entry uses the expected encryption algorithm.
Zip(const std::string &filename)
Open a zip archive from a file.
auto end() const -> Iterator
Get an end-of-stream iterator.
Definition Zip.hpp:144
auto load(const Entry &entry, std::size_t count=std::numeric_limits< std::size_t >::max()) const -> std::vector< std::uint8_t >
Load at most count bytes of the given entry's raw data.
void changeKeys(std::ostream &os, const Keys &oldKeys, const Keys &newKeys, Progress &progress) const
Copy the zip file into os changing the encrypted data using the given keys.
auto operator[](std::size_t index) const -> Entry
Get the entry at the given index.
auto seek(const Entry &entry) const -> std::istream &
Set the underlying stream's input position indicator at the beginning the given entry's raw data.
Zip(std::istream &stream)
Open a zip archive from an already opened input stream.
void decrypt(std::ostream &os, const Keys &keys, Progress &progress) const
Copy the zip file into os removing encryption using the given keys.
Encryption
Encryption algorithm.
Definition Zip.hpp:33
@ Traditional
Traditional PKWARE encryption (ZipCrypto), vulnerable to known plaintext attack.
Definition Zip.hpp:35
@ None
No encryption.
Definition Zip.hpp:34
@ Unsupported
Other encryption (DES, RC2, 3DES, AES, Blowfish, Twofish, RC4)
Definition Zip.hpp:36
Information about a zip entry.
Definition Zip.hpp:59
Encryption encryption
Encryption method.
Definition Zip.hpp:61
std::uint64_t offset
Offset of local file header.
Definition Zip.hpp:64
std::uint64_t packedSize
Packed data size.
Definition Zip.hpp:65
std::uint8_t checkByte
Last byte of the encryption header after decryption.
Definition Zip.hpp:67
std::uint64_t uncompressedSize
Uncompressed data size.
Definition Zip.hpp:66
std::string name
File name.
Definition Zip.hpp:60
Compression compression
Compression method.
Definition Zip.hpp:62
std::uint32_t crc32
CRC-32 checksum.
Definition Zip.hpp:63