monotone

monotone Mtn Source Tree

Root/src/gzip.hh

1/*************************************************
2* Gzip Compressor Header File *
3* (C) 2001 Peter J Jones (pjones@pmade.org) *
4* 2001-2004 Jack Lloyd *
5*************************************************/
6
7#ifndef BOTAN_EXT_GZIP_H__
8#define BOTAN_EXT_GZIP_H__
9
10#include <botan/version.h>
11#include <botan/filter.h>
12#include <botan/pipe.h>
13
14namespace Botan {
15
16#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,12) && \
17 BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,9,4)
18// Botan versions between 1.7.12 and 1.9.3 (including) keep their
19// Memory_Exception private. Give this gzip implementation something
20// compatible to work with.
21class Memory_Exhaustion : public Exception
22{
23public:
24 Memory_Exhaustion() :
25 Exception("Ran out of memory, allocation failed") {}
26};
27#endif
28
29namespace GZIP {
30
31 /* A basic header - we only need to set the IDs and compression method */
32 const byte GZIP_HEADER[] = {
33 0x1f, 0x8b, /* Magic ID bytes */
34 0x08, /* Compression method of 'deflate' */
35 0x00, /* Flags all empty */
36 0x00, 0x00, 0x00, 0x00, /* MTIME */
37 0x00, /* Extra flags */
38 0xff, /* Operating system (unknown) */
39 };
40
41 const unsigned int HEADER_POS_OS = 9;
42
43 const unsigned int FOOTER_LENGTH = 8;
44
45}
46
47#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,9,11)
48typedef size_t filter_length_t;
49#else
50typedef u32bit filter_length_t;
51#endif
52
53/*************************************************
54* Gzip Compression Filter *
55*************************************************/
56class Gzip_Compression : public Filter
57 {
58 public:
59 void write(const byte input[], filter_length_t length);
60 void start_msg();
61 void end_msg();
62 std::string name() const { return "Gzip_Compression"; }
63
64 Gzip_Compression(u32bit = 1);
65 ~Gzip_Compression();
66 private:
67 void clear();
68 void put_header();
69 void put_footer();
70 const u32bit level;
71 SecureVector<byte> buffer;
72 class Zlib_Stream* zlib;
73 Pipe pipe; /* A pipe for the crc32 processing */
74 u32bit count;
75 };
76
77/*************************************************
78* Gzip Decompression Filter *
79*************************************************/
80class Gzip_Decompression : public Filter
81 {
82 public:
83 void write(const byte input[], filter_length_t length);
84 void start_msg();
85 void end_msg();
86 std::string name() const { return "Gzip_Decompression"; }
87
88 Gzip_Decompression();
89 ~Gzip_Decompression();
90 private:
91 u32bit eat_footer(const byte input[], u32bit length);
92 void check_footer();
93 void clear();
94 SecureVector<byte> buffer;
95 class Zlib_Stream* zlib;
96 bool no_writes;
97 u32bit pos; /* Current position in the message */
98 Pipe pipe; /* A pipe for the crc32 processing */
99 u32bit datacount; /* Amount of uncompressed output */
100 SecureVector<byte> footer;
101 bool in_footer;
102 };
103
104}
105
106#endif
107
108// Local Variables:
109// mode: C++
110// fill-column: 76
111// c-file-style: "gnu"
112// indent-tabs-mode: nil
113// End:
114// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status