diff options
author | Marcus Brinkmann <[email protected]> | 2017-11-25 20:22:57 +0100 |
---|---|---|
committer | Marcus Brinkmann <[email protected]> | 2017-11-25 20:22:57 +0100 |
commit | 34aa73d0f9c3bf817a0a46889206003f0becd3f1 (patch) | |
tree | 18b9858383756fb12727d7cbed61d6b9ace0fd39 /src/lib/compression/compression.cpp | |
parent | c23eb5eb3463459654e0f6601a3b2304eb2076ee (diff) |
Add create and create_or_throw factories for Compression_Algorithm and Decompression_Algorithm.
Diffstat (limited to 'src/lib/compression/compression.cpp')
-rw-r--r-- | src/lib/compression/compression.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/lib/compression/compression.cpp b/src/lib/compression/compression.cpp index ded6b3b08..361bf7dd3 100644 --- a/src/lib/compression/compression.cpp +++ b/src/lib/compression/compression.cpp @@ -7,6 +7,7 @@ #include <botan/compression.h> #include <botan/mem_ops.h> +#include <botan/exceptn.h> #include <cstdlib> #if defined(BOTAN_HAS_ZLIB) @@ -48,6 +49,25 @@ Compression_Algorithm* make_compressor(const std::string& name) return nullptr; } +//static +std::unique_ptr<Compression_Algorithm> +Compression_Algorithm::create(const std::string& algo) + { + std::unique_ptr<Compression_Algorithm> compressor(make_compressor(algo)); + return compressor; + } + +//static +std::unique_ptr<Compression_Algorithm> +Compression_Algorithm::create_or_throw(const std::string& algo) + { + if(auto compressor = Compression_Algorithm::create(algo)) + { + return compressor; + } + throw Lookup_Error("Compression", algo, ""); + } + Decompression_Algorithm* make_decompressor(const std::string& name) { #if defined(BOTAN_HAS_ZLIB) @@ -73,5 +93,24 @@ Decompression_Algorithm* make_decompressor(const std::string& name) return nullptr; } +//static +std::unique_ptr<Decompression_Algorithm> +Decompression_Algorithm::create(const std::string& algo) + { + std::unique_ptr<Decompression_Algorithm> decompressor(make_decompressor(algo)); + return decompressor; + } + +//static +std::unique_ptr<Decompression_Algorithm> +Decompression_Algorithm::create_or_throw(const std::string& algo) + { + if(auto decompressor = Decompression_Algorithm::create(algo)) + { + return decompressor; + } + throw Lookup_Error("Decompression", algo, ""); + } } + |