aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/compression/compression.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-11-18 13:42:36 +0000
committerlloyd <[email protected]>2014-11-18 13:42:36 +0000
commitdec2e0d9e493b53c48ca26b47028ab309d3cc586 (patch)
tree2242f756ece5e1a9cc728dc208c154e694314d5a /src/lib/compression/compression.h
parentb5e2a1ce3044084e43ff523f148b0cc8e95ce283 (diff)
Convert compression filters to in-place transforms and refactor
to minimize the amount of logic needed in the files specific to each library.
Diffstat (limited to 'src/lib/compression/compression.h')
-rw-r--r--src/lib/compression/compression.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/lib/compression/compression.h b/src/lib/compression/compression.h
new file mode 100644
index 000000000..10c7f1a64
--- /dev/null
+++ b/src/lib/compression/compression.h
@@ -0,0 +1,99 @@
+/*
+* Compression Transform
+* (C) 2014 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_COMPRESSION_TRANSFORM_H__
+#define BOTAN_COMPRESSION_TRANSFORM_H__
+
+#include <botan/transform.h>
+
+namespace Botan {
+
+class BOTAN_DLL Compressor_Transformation : public Transformation
+ {
+ public:
+ size_t update_granularity() const override { return 1; }
+
+ size_t minimum_final_size() const override { return 0; }
+
+ size_t default_nonce_length() const override { return 0; }
+
+ bool valid_nonce_length(size_t nonce_len) const override
+ { return nonce_len == 0; }
+
+ virtual void flush(secure_vector<byte>& buf, size_t offset = 0) { update(buf, offset); }
+
+ size_t output_length(size_t) const override
+ {
+ throw std::runtime_error(name() + " output length indeterminate");
+ }
+ };
+
+class Compression_Stream
+ {
+ public:
+ virtual ~Compression_Stream() {}
+
+ virtual void next_in(byte* b, size_t len) = 0;
+
+ virtual void next_out(byte* b, size_t len) = 0;
+
+ virtual size_t avail_in() const = 0;
+
+ virtual size_t avail_out() const = 0;
+
+ virtual u32bit run_flag() const = 0;
+ virtual u32bit flush_flag() const = 0;
+ virtual u32bit finish_flag() const = 0;
+
+ virtual bool run(u32bit flags) = 0;
+ };
+
+class BOTAN_DLL Stream_Compression : public Compressor_Transformation
+ {
+ public:
+ void update(secure_vector<byte>& buf, size_t offset = 0) override;
+
+ void flush(secure_vector<byte>& buf, size_t offset = 0) override;
+
+ void finish(secure_vector<byte>& buf, size_t offset = 0) override;
+
+ void clear() override;
+
+ private:
+ secure_vector<byte> start_raw(const byte[], size_t) override;
+
+ void process(secure_vector<byte>& buf, size_t offset, u32bit flags);
+
+ virtual Compression_Stream* make_stream() const = 0;
+
+ secure_vector<byte> m_buffer;
+ std::unique_ptr<Compression_Stream> m_stream;
+ };
+
+class BOTAN_DLL Stream_Decompression : public Compressor_Transformation
+ {
+ public:
+ void update(secure_vector<byte>& buf, size_t offset = 0) override;
+
+ void finish(secure_vector<byte>& buf, size_t offset = 0) override;
+
+ void clear() override;
+
+ private:
+ secure_vector<byte> start_raw(const byte[], size_t) override;
+
+ void process(secure_vector<byte>& buf, size_t offset, u32bit flags);
+
+ virtual Compression_Stream* make_stream() const = 0;
+
+ secure_vector<byte> m_buffer;
+ std::unique_ptr<Compression_Stream> m_stream;
+ };
+
+}
+
+#endif