libarchive/libarchive — pull request #43 by kwk (2013-07-02 08:29:39+00:00)
Title: Detect encrypted archives/entries

For a an extra discussion about this pull request, please see libarchive-discuss mailing list (https://groups.google.com/d/msg/libarchive-discuss/ggz04EjnVG8/deLDerhMy90J)

This change introduces two new functions:

1. int archive_read_has_encrypted_entries(struct archive *):
------------------------------------------------------------
This function returns 1 if the archive contains at least one encrypted
entry; otherwise 0 is returned.

This functionality works after the first call to
archive_read_next_header(), at least for the Zip format. All other
formats will return 0 currently. Need to find out if the other formats
also have the ability to check for encrypted entries just by reading the
first header. For Zip it works that way because on the first read
heaeder, the central directory is also read once (see
slurp_central_directory()).

2. int archive_entry_is_encrypted(struct archive_entry *):
----------------------------------------------------------
This function returns 1 if the current entry (as read by
archive_read_next_header()) is encrypted; othweise 0 i returned.

Currently this function only is implemented for Zip but it should be
easily adoptible by other formats. Everything the other formats have to
do is set the archive_entry::is_encrypted flag to ARCHIVE_ENTRY_ENCRYPTED.

One thing to note is that this change doesn't introduce the ability to
extract encrypted archives. But it allows applications to query if an
archive or an entry is encrypted and lets the application decide what
to do.

I've added a test to check that this functionality is working as
expected for encrypted zip files. The password to decrypt the uudecoded
file "test_read_format_zip_encryption.zip.uu" is "tester".