aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/compression
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/compression')
-rw-r--r--src/lib/compression/bzip2/bzip2.cpp2
-rw-r--r--src/lib/compression/comp_util.h5
-rw-r--r--src/lib/compression/compression.cpp59
-rw-r--r--src/lib/compression/compression.h10
-rw-r--r--src/lib/compression/lzma/lzma.cpp2
-rw-r--r--src/lib/compression/zlib/zlib.cpp4
6 files changed, 35 insertions, 47 deletions
diff --git a/src/lib/compression/bzip2/bzip2.cpp b/src/lib/compression/bzip2/bzip2.cpp
index 471635e3e..2d1617bce 100644
--- a/src/lib/compression/bzip2/bzip2.cpp
+++ b/src/lib/compression/bzip2/bzip2.cpp
@@ -15,6 +15,8 @@
namespace Botan {
+BOTAN_REGISTER_COMPRESSION(Bzip2_Compression, Bzip2_Decompression);
+
namespace {
class Bzip2_Stream : public Zlib_Style_Stream<bz_stream, char>
diff --git a/src/lib/compression/comp_util.h b/src/lib/compression/comp_util.h
index 6e1ee1671..963eae642 100644
--- a/src/lib/compression/comp_util.h
+++ b/src/lib/compression/comp_util.h
@@ -9,6 +9,7 @@
#define BOTAN_COMPRESSION_UTILS_H__
#include <botan/compression.h>
+#include <botan/algo_registry.h>
#include <memory>
#include <unordered_map>
@@ -84,6 +85,10 @@ class Zlib_Style_Stream : public Compression_Stream
std::unique_ptr<Compression_Alloc_Info> m_allocs;
};
+#define BOTAN_REGISTER_COMPRESSION(C, D) \
+ BOTAN_REGISTER_T_1LEN(Transform, C, 9) \
+ BOTAN_REGISTER_T_NOARGS(Transform, D)
+
}
#endif
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()
diff --git a/src/lib/compression/compression.h b/src/lib/compression/compression.h
index b38d94f64..f70252cbe 100644
--- a/src/lib/compression/compression.h
+++ b/src/lib/compression/compression.h
@@ -12,7 +12,7 @@
namespace Botan {
-class BOTAN_DLL Compressor_Transformation : public Transformation
+class BOTAN_DLL Compressor_Transform : public Transform
{
public:
size_t update_granularity() const override { return 1; }
@@ -32,8 +32,8 @@ class BOTAN_DLL Compressor_Transformation : public Transformation
}
};
-BOTAN_DLL Compressor_Transformation* make_compressor(const std::string& type, size_t level);
-BOTAN_DLL Compressor_Transformation* make_decompressor(const std::string& type);
+BOTAN_DLL Transform* make_compressor(const std::string& type, size_t level);
+BOTAN_DLL Transform* make_decompressor(const std::string& type);
class Compression_Stream
{
@@ -55,7 +55,7 @@ class Compression_Stream
virtual bool run(u32bit flags) = 0;
};
-class BOTAN_DLL Stream_Compression : public Compressor_Transformation
+class BOTAN_DLL Stream_Compression : public Compressor_Transform
{
public:
void update(secure_vector<byte>& buf, size_t offset = 0) override;
@@ -76,7 +76,7 @@ class BOTAN_DLL Stream_Compression : public Compressor_Transformation
std::unique_ptr<Compression_Stream> m_stream;
};
-class BOTAN_DLL Stream_Decompression : public Compressor_Transformation
+class BOTAN_DLL Stream_Decompression : public Compressor_Transform
{
public:
void update(secure_vector<byte>& buf, size_t offset = 0) override;
diff --git a/src/lib/compression/lzma/lzma.cpp b/src/lib/compression/lzma/lzma.cpp
index 0aadf1513..69d73a3a1 100644
--- a/src/lib/compression/lzma/lzma.cpp
+++ b/src/lib/compression/lzma/lzma.cpp
@@ -14,6 +14,8 @@
namespace Botan {
+BOTAN_REGISTER_COMPRESSION(LZMA_Compression, LZMA_Decompression);
+
namespace {
class LZMA_Stream : public Zlib_Style_Stream<lzma_stream, byte>
diff --git a/src/lib/compression/zlib/zlib.cpp b/src/lib/compression/zlib/zlib.cpp
index 8c94e4331..24e8721e3 100644
--- a/src/lib/compression/zlib/zlib.cpp
+++ b/src/lib/compression/zlib/zlib.cpp
@@ -14,6 +14,10 @@
namespace Botan {
+BOTAN_REGISTER_COMPRESSION(Zlib_Compression, Zlib_Decompression);
+BOTAN_REGISTER_COMPRESSION(Gzip_Compression, Gzip_Decompression);
+BOTAN_REGISTER_COMPRESSION(Deflate_Compression, Deflate_Decompression);
+
namespace {
class Zlib_Stream : public Zlib_Style_Stream<z_stream, Bytef>