rikyoz / bit7z

A C++ static library offering a clean and simple interface to the 7-zip shared libraries.
https://rikyoz.github.io/bit7z
Mozilla Public License 2.0
602 stars 110 forks source link

[Feature Request]: Adding a function to determine whether the metadata is encrypted #164

Closed ygqs250 closed 9 months ago

ygqs250 commented 10 months ago

Feature description

Adding a function to determine whether the metadata is encrypted? Now bit7z can only use exceptions to determine whether the metadata is encrypted.

Additional context

No response

Code of Conduct

rikyoz commented 10 months ago

Hi!

Thanks for the suggestion!

I've just pushed a commit (https://github.com/rikyoz/bit7z/commit/d19423420df7ab6da8bbf2b83076a25b224bafb9) that adds two static functions to the BitArchiveReader class:

template< typename T >
auto BitArchiveReader::isHeaderEncrypted( const Bit7zLibrary& lib,
                                          T&& in_archive,
                                          const BitInFormat& format ) -> bool;

template< typename T >
auto BitArchiveReader::isEncrypted( const Bit7zLibrary& lib,
                                    T&& in_archive,
                                    const BitInFormat& format ) -> bool;

They're template functions so that they can accept either a file path (string), a buffer, or a standard stream of the archive to be checked.

BitArchiveReader::isHeaderEncrypted checks whether the archive is fully encrypted (header included), and hence it needs a password to be opened.

BitArchiveReader::isEncrypted checks whether the archive contains only encrypted files, but can be opened without a password (plain headers).

These functions will be included in the stable version of bit7z v4.

rikyoz commented 9 months ago

Implemented in v4.0.0.