diff options
author | Tomasz Frydrych <[email protected]> | 2017-05-01 15:03:52 +0200 |
---|---|---|
committer | Tomasz Frydrych <[email protected]> | 2017-05-01 15:03:52 +0200 |
commit | 87c0fae706140b0a2a7a3fda9dd813474172fa2a (patch) | |
tree | 28930efab4d290dcebb89666d46050edd06703fd /src/cli/compress.cpp | |
parent | 29cc6bebe132a34f882d450b35a69bf71bb3e27b (diff) |
Reformat code with astyle + fix code style
Diffstat (limited to 'src/cli/compress.cpp')
-rw-r--r-- | src/cli/compress.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/cli/compress.cpp b/src/cli/compress.cpp index d5b2c4736..6ee6398ee 100644 --- a/src/cli/compress.cpp +++ b/src/cli/compress.cpp @@ -7,7 +7,7 @@ #include "cli.h" #if defined(BOTAN_HAS_COMPRESSION) - #include <botan/compression.h> + #include <botan/compression.h> #endif namespace Botan_CLI { @@ -19,15 +19,15 @@ class Compress final : public Command public: Compress() : Command("compress --type=gzip --level=6 --buf-size=8192 file") {} - std::string output_filename(const std::string& input_fsname, - const std::string& comp_type) + std::string output_filename(const std::string& input_fsname, const std::string& comp_type) { - const std::map<std::string, std::string> suffixes = { - { "zlib", "zlib" }, - { "gzip", "gz" }, - { "bzip2", "bz2" }, - { "lzma", "xz" }, - }; + const std::map<std::string, std::string> suffixes = + { + { "zlib", "zlib" }, + { "gzip", "gz" }, + { "bzip2", "bz2" }, + { "lzma", "xz" }, + }; auto suffix_info = suffixes.find(comp_type); if(suffixes.count(comp_type) == 0) @@ -103,10 +103,12 @@ class Decompress final : public Command { auto last_dot = in_file.find_last_of('.'); if(last_dot == std::string::npos || last_dot == 0) + { throw CLI_Error("No extension detected in filename '" + in_file + "'"); + } out_file = in_file.substr(0, last_dot); - suffix = in_file.substr(last_dot+1, std::string::npos); + suffix = in_file.substr(last_dot + 1, std::string::npos); } void go() override @@ -119,18 +121,24 @@ class Decompress final : public Command std::ifstream in(in_file); if(!in.good()) + { throw CLI_IO_Error("reading", in_file); + } std::unique_ptr<Botan::Decompression_Algorithm> decompress; decompress.reset(Botan::make_decompressor(suffix)); if(!decompress) + { throw CLI_Error_Unsupported("Decompression", suffix); + } std::ofstream out(out_file); if(!out.good()) + { throw CLI_IO_Error("writing", out_file); + } Botan::secure_vector<uint8_t> buf; |