aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/compression/compression.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-01-28 04:32:10 +0000
committerlloyd <[email protected]>2015-01-28 04:32:10 +0000
commit7b56f1bd570dc684ffd7c945dee0d9b5480354ff (patch)
tree0c50ad534280a292a1b76daee9a19b34cfd96367 /src/lib/compression/compression.cpp
parentb8fa304ec981d273c45d7ef31705d65ccfb00cc1 (diff)
Add a runtime map of string->func() which when called return
Transforms and BlockCiphers. Registration for all types is done at startup but is very cheap as just a std::function and a std::map entry are created, no actual objects are created until needed. This is a huge improvement over Algorithm_Factory which used T::clone() as the function and thus kept a prototype object of each type in memory. Replace existing lookup mechanisms for ciphers, AEADs, and compression to use the transform lookup. The existing Engine framework remains in place for BlockCipher, but the engines now just call to the registry instead of having hardcoded lookups. s/Transformation/Transform/ with typedefs for compatability. Remove lib/selftest code (for runtime selftesting): not the right approach.
Diffstat (limited to 'src/lib/compression/compression.cpp')
-rw-r--r--src/lib/compression/compression.cpp59
1 files changed, 17 insertions, 42 deletions
diff --git a/src/lib/compression/compression.cpp b/src/lib/compression/compression.cpp
index 428271e9a..e5221aba6 100644
--- a/src/lib/compression/compression.cpp
+++ b/src/lib/compression/compression.cpp
@@ -6,67 +6,42 @@
*/
#include <botan/compression.h>
-
-#if defined(BOTAN_HAS_ZLIB_TRANSFORM)
- #include <botan/zlib.h>
-#endif
-
-#if defined(BOTAN_HAS_BZIP2_TRANSFORM)
- #include <botan/bzip2.h>
-#endif
-
-#if defined(BOTAN_HAS_LZMA_TRANSFORM)
- #include <botan/lzma.h>
-#endif
+#include <botan/algo_registry.h>
namespace Botan {
-Compressor_Transformation* make_compressor(const std::string& type, size_t level)
+Transform* make_compressor(const std::string& type, size_t level)
{
-#if defined(BOTAN_HAS_ZLIB_TRANSFORM)
+ const std::string comp_suffix = "_Compression(" + std::to_string(level) + ")";
+
if(type == "zlib")
- return new Zlib_Compression(level);
+ return get_transform("Zlib" + comp_suffix);
if(type == "deflate")
- return new Deflate_Compression(level);
+ return get_transform("Deflate" + comp_suffix);
if(type == "gzip" || type == "gz")
- return new Gzip_Compression(level);
-#endif
-
-#if defined(BOTAN_HAS_BZIP2_TRANSFORM)
+ return get_transform("Gzip" + comp_suffix);
if(type == "bzip2" || type == "bz2")
- return new Bzip2_Compression(level);
-#endif
-
-#if defined(BOTAN_HAS_LZMA_TRANSFORM)
+ return get_transform("Bzip2", comp_suffix);
if(type == "lzma" || type == "xz")
- return new LZMA_Compression(level);
-#endif
+ return get_transform("LZMA", comp_suffix);
- throw std::runtime_error("Unknown compression type " + type);
+ return nullptr;
}
-Compressor_Transformation* make_decompressor(const std::string& type)
+Transform* make_decompressor(const std::string& type)
{
-#if defined(BOTAN_HAS_ZLIB_TRANSFORM)
if(type == "zlib")
- return new Zlib_Decompression;
+ return get_transform("Zlib_Decompression");
if(type == "deflate")
- return new Deflate_Decompression;
+ return get_transform("Deflate_Decompression");
if(type == "gzip" || type == "gz")
- return new Gzip_Decompression;
-#endif
-
-#if defined(BOTAN_HAS_BZIP2_TRANSFORM)
+ return get_transform("Gzip_Decompression");
if(type == "bzip2" || type == "bz2")
- return new Bzip2_Decompression;
-#endif
-
-#if defined(BOTAN_HAS_LZMA_TRANSFORM)
+ return get_transform("Bzip2_Decompression");
if(type == "lzma" || type == "xz")
- return new LZMA_Decompression;
-#endif
+ return get_transform("LZMA_Decompression");
- throw std::runtime_error("Unknown compression type " + type);
+ return nullptr;
}
void Stream_Compression::clear()