Skip to content

Commit

Permalink
Show compression method when deciphering a single entry
Browse files Browse the repository at this point in the history
  • Loading branch information
kimci86 committed May 17, 2024
1 parent 72b2f4a commit 3ef515a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Other options:
--version Show version information and exit
-h, --help Show this help and exit)_";

auto getCompressionDescription(Zip::Compression compression) -> std::string;
void listEntries(const std::string& archiveFilename);

} // namespace
Expand Down Expand Up @@ -211,11 +212,13 @@ try
// decipher
if (args.decipheredFile)
{
std::cout << "[" << put_time << "] Writing deciphered data " << *args.decipheredFile << " (maybe compressed)";
std::cout << "[" << put_time << "] Writing deciphered data " << *args.decipheredFile;
if (args.keepHeader)
std::cout << " with encryption header";
std::cout << std::endl;

auto compression = std::optional<Zip::Compression>{};

{
auto cipherstream = openInput(args.cipherArchive ? *args.cipherArchive : *args.cipherFile);
auto ciphersize = std::numeric_limits<std::size_t>::max();
Expand All @@ -225,6 +228,7 @@ try
const auto archive = Zip{cipherstream};
const auto entry = args.cipherFile ? archive[*args.cipherFile] : archive[*args.cipherIndex];
Zip::checkEncryption(entry, Zip::Encryption::Traditional);
compression = entry.compression;

archive.seek(entry);
ciphersize = entry.packedSize;
Expand All @@ -237,7 +241,15 @@ try
keys);
}

std::cout << "Wrote deciphered data." << std::endl;
std::cout << "Wrote deciphered data";
if (compression)
{
if (compression == Zip::Compression::Store)
std::cout << " (not compressed)";
else
std::cout << " (compressed with " << getCompressionDescription(*compression) << " method)";
}
std::cout << "." << std::endl;
}

// decrypt
Expand Down

0 comments on commit 3ef515a

Please sign in to comment.