-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgzip.hh
84 lines (70 loc) · 2.23 KB
/
gzip.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*************************************************
* Gzip Compressor Header File *
* (C) 2001 Peter J Jones (pjones@pmade.org) *
* 2001-2004 Jack Lloyd *
*************************************************/
#ifndef BOTAN_EXT_GZIP_H__
#define BOTAN_EXT_GZIP_H__
#include <botan/filter.h>
#include <botan/pipe.h>
namespace Botan {
namespace GZIP {
/* A basic header - we only need to set the IDs and compression method */
const byte GZIP_HEADER[] = {
0x1f, 0x8b, /* Magic ID bytes */
0x08, /* Compression method of 'deflate' */
0x00, /* Flags all empty */
0x00, 0x00, 0x00, 0x00, /* MTIME */
0x00, /* Extra flags */
0xff, /* Operating system (unknown) */
};
const unsigned int HEADER_POS_OS = 9;
const unsigned int FOOTER_LENGTH = 8;
}
/*************************************************
* Gzip Compression Filter *
*************************************************/
class Gzip_Compression : public Filter
{
public:
void write(const byte input[], u32bit length);
void start_msg();
void end_msg();
Gzip_Compression(u32bit = 1);
~Gzip_Compression();
private:
void clear();
void put_header();
void put_footer();
const u32bit level;
SecureVector<byte> buffer;
class Zlib_Stream* zlib;
Pipe pipe; /* A pipe for the crc32 processing */
u32bit count;
};
/*************************************************
* Gzip Decompression Filter *
*************************************************/
class Gzip_Decompression : public Filter
{
public:
void write(const byte input[], u32bit length);
void start_msg();
void end_msg();
Gzip_Decompression();
~Gzip_Decompression();
private:
u32bit eat_footer(const byte input[], u32bit length);
void check_footer();
void clear();
SecureVector<byte> buffer;
class Zlib_Stream* zlib;
bool no_writes;
u32bit pos; /* Current position in the message */
Pipe pipe; /* A pipe for the crc32 processing */
u32bit datacount; /* Amount of uncompressed output */
SecureVector<byte> footer;
bool in_footer;
};
}
#endif