aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-12-28 18:38:06 +0000
committerlloyd <[email protected]>2011-12-28 18:38:06 +0000
commitf29ca5483570aa0974b484e5cfebaecf62124133 (patch)
treec7993d13746ea6632cc27758d118a4ff96de5d29 /src
parenta815e21417cd6d38d8ac2bfa0f978fe7b898e6c0 (diff)
Add support for raw deflate in the zlib filter
Diffstat (limited to 'src')
-rw-r--r--src/filters/zlib/zlib.cpp31
-rw-r--r--src/filters/zlib/zlib.h16
2 files changed, 35 insertions, 12 deletions
diff --git a/src/filters/zlib/zlib.cpp b/src/filters/zlib/zlib.cpp
index 0f88b5558..517660e3b 100644
--- a/src/filters/zlib/zlib.cpp
+++ b/src/filters/zlib/zlib.cpp
@@ -91,10 +91,12 @@ class Zlib_Stream
/*
* Zlib_Compression Constructor
*/
-Zlib_Compression::Zlib_Compression(size_t l) :
- level((l >= 9) ? 9 : l), buffer(DEFAULT_BUFFERSIZE)
+Zlib_Compression::Zlib_Compression(size_t l, bool raw_deflate) :
+ level((l >= 9) ? 9 : l),
+ raw_deflate(raw_deflate),
+ buffer(DEFAULT_BUFFERSIZE),
+ zlib(0)
{
- zlib = 0;
}
/*
@@ -104,7 +106,17 @@ void Zlib_Compression::start_msg()
{
clear();
zlib = new Zlib_Stream;
- if(deflateInit(&(zlib->stream), level) != Z_OK)
+
+ int res = deflateInit2(&(zlib->stream),
+ level,
+ Z_DEFLATED,
+ (raw_deflate ? -15 : 15),
+ 8,
+ Z_DEFAULT_STRATEGY);
+
+ if(res == Z_STREAM_ERROR)
+ throw Invalid_Argument("Bad setting in deflateInit2");
+ else if(res != Z_OK)
throw Memory_Exhaustion();
}
@@ -185,10 +197,12 @@ void Zlib_Compression::clear()
/*
* Zlib_Decompression Constructor
*/
-Zlib_Decompression::Zlib_Decompression() : buffer(DEFAULT_BUFFERSIZE)
+Zlib_Decompression::Zlib_Decompression(bool raw_deflate) :
+ raw_deflate(raw_deflate),
+ buffer(DEFAULT_BUFFERSIZE),
+ zlib(0),
+ no_writes(true)
{
- zlib = 0;
- no_writes = true;
}
/*
@@ -198,7 +212,8 @@ void Zlib_Decompression::start_msg()
{
clear();
zlib = new Zlib_Stream;
- if(inflateInit(&(zlib->stream)) != Z_OK)
+
+ if(inflateInit2(&(zlib->stream), (raw_deflate ? -15 : 15)) != Z_OK)
throw Memory_Exhaustion();
}
diff --git a/src/filters/zlib/zlib.h b/src/filters/zlib/zlib.h
index 77ec5eecc..60117f2bc 100644
--- a/src/filters/zlib/zlib.h
+++ b/src/filters/zlib/zlib.h
@@ -31,15 +31,20 @@ class BOTAN_DLL Zlib_Compression : public Filter
void flush();
/**
- @param level how much effort to use on compressing (0 to 9);
- higher levels are slower but tend to give better compression
+ * @param level how much effort to use on compressing (0 to 9);
+ * higher levels are slower but tend to give better
+ * compression
+ * @param raw_deflate if true no zlib header/trailer will be used
*/
- Zlib_Compression(size_t level = 6);
+ Zlib_Compression(size_t level = 6,
+ bool raw_deflate = false);
~Zlib_Compression() { clear(); }
private:
void clear();
const size_t level;
+ const bool raw_deflate;
+
SecureVector<byte> buffer;
class Zlib_Stream* zlib;
};
@@ -56,10 +61,13 @@ class BOTAN_DLL Zlib_Decompression : public Filter
void start_msg();
void end_msg();
- Zlib_Decompression();
+ Zlib_Decompression(bool raw_deflate = false);
~Zlib_Decompression() { clear(); }
private:
void clear();
+
+ const bool raw_deflate;
+
SecureVector<byte> buffer;
class Zlib_Stream* zlib;
bool no_writes;