aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/compression/bzip2
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-04-12 23:03:14 -0400
committerJack Lloyd <[email protected]>2016-04-21 09:18:54 -0400
commit8b85b7805151ab8fce5ac9d214c71c4eeb3d6075 (patch)
tree40cbc2af481dfc2f84e32330308523a5e8f68e44 /src/lib/compression/bzip2
parenta4358c96a0de1ab7afc0b437ab79bfc35f2e1824 (diff)
Remove Transform base class
With sufficient squinting, Transform provided an abstract base interface that covered both cipher modes and compression algorithms. However it mapped on neither of them particularly well. In addition this API had the same problem that has made me dislike the Pipe/Filter API: given a Transform&, what does it do when you put bits in? Maybe it encrypts. Maybe it compresses. It's a floor wax and a dessert topping! Currently the Cipher_Mode interface is left mostly unchanged, with the APIs previously on Transform just moved down the type hierarchy. I think there are some definite improvements possible here, wrt handling of in-place encryption, but left for a later commit. The compression API is split into two types, Compression_Algorithm and Decompression_Algorithm. Compression_Algorithm's start() call takes the compression level, allowing varying compressions with a single object. And flushing the compression state is moved to a bool param on `Compression_Algorithm::update`. All the nonsense WRT compression algorithms having zero length nonces, input granularity rules, etc as a result of using the Transform interface goes away.
Diffstat (limited to 'src/lib/compression/bzip2')
-rw-r--r--src/lib/compression/bzip2/bzip2.cpp12
-rw-r--r--src/lib/compression/bzip2/bzip2.h14
-rw-r--r--src/lib/compression/bzip2/info.txt2
3 files changed, 12 insertions, 16 deletions
diff --git a/src/lib/compression/bzip2/bzip2.cpp b/src/lib/compression/bzip2/bzip2.cpp
index d9ada84f6..565eb09fc 100644
--- a/src/lib/compression/bzip2/bzip2.cpp
+++ b/src/lib/compression/bzip2/bzip2.cpp
@@ -39,6 +39,14 @@ class Bzip2_Compression_Stream : public Bzip2_Stream
public:
explicit Bzip2_Compression_Stream(size_t block_size)
{
+ /*
+ * Defaults to 900k blocks as the computation cost of
+ * compression is not overly affected by the size, though
+ * more memory is required.
+ */
+ if(block_size == 0 || block_size >= 9)
+ block_size = 9;
+
int rc = BZ2_bzCompressInit(streamp(), block_size, 0, 0);
if(rc == BZ_MEM_ERROR)
@@ -98,9 +106,9 @@ class Bzip2_Decompression_Stream : public Bzip2_Stream
}
-Compression_Stream* Bzip2_Compression::make_stream() const
+Compression_Stream* Bzip2_Compression::make_stream(size_t comp_level) const
{
- return new Bzip2_Compression_Stream(m_block_size);
+ return new Bzip2_Compression_Stream(comp_level);
}
Compression_Stream* Bzip2_Decompression::make_stream() const
diff --git a/src/lib/compression/bzip2/bzip2.h b/src/lib/compression/bzip2/bzip2.h
index 06c80cb8e..18216f7eb 100644
--- a/src/lib/compression/bzip2/bzip2.h
+++ b/src/lib/compression/bzip2/bzip2.h
@@ -19,21 +19,9 @@ namespace Botan {
class BOTAN_DLL Bzip2_Compression final : public Stream_Compression
{
public:
- /**
- * @param block_size in 1024 KiB increments, in range from 1 to 9.
- *
- * Lowering this does not noticably modify the compression or
- * decompression speed, though less memory is required for both
- * compression and decompression.
- */
- Bzip2_Compression(size_t block_size = 9) : m_block_size(block_size) {}
-
std::string name() const override { return "Bzip2_Compression"; }
-
private:
- Compression_Stream* make_stream() const override;
-
- const size_t m_block_size;
+ Compression_Stream* make_stream(size_t comp_level) const override;
};
/**
diff --git a/src/lib/compression/bzip2/info.txt b/src/lib/compression/bzip2/info.txt
index ea2efa6f1..bc8d780be 100644
--- a/src/lib/compression/bzip2/info.txt
+++ b/src/lib/compression/bzip2/info.txt
@@ -1,4 +1,4 @@
-define BZIP2_TRANSFORM 20141118
+define BZIP2 20160412
load_on vendor