Botan 1.10.17

Public Member Functions | Protected Member Functions | List of all members
Botan::Zlib_Compression Class Reference

`#include <zlib.h>`

Inheritance diagram for Botan::Zlib_Compression:

## Public Member Functions
virtual bool | attachable ()
void | end_msg ()
void | flush ()
std::string | name () const
void | start_msg ()
void | write (const byte input[], size_t length)
| Zlib_Compression (size_t level=6)
| ~Zlib_Compression ()

## Protected Member Functions
void | send (const byte in[], size_t length)
void | send (byte in)
void | send (const MemoryRegion< byte > &in)
void | send (const MemoryRegion< byte > &in, size_t length)

## Detailed Description

Zlib Compression Filter

Definition at line 19 of file zlib.h.

## Constructor & Destructor Documentation

## ◆ Zlib_Compression()

Botan::Zlib_Compression::Zlib_Compression | ( | size_t | level = `6` | ) |

Parameters

  level | how much effort to use on compressing (0 to 9); higher levels are slower but tend to give better compression

Definition at line 94 of file zlib.cpp.

94 :
95 level((l >= 9) ? 9 : l), buffer(DEFAULT_BUFFERSIZE)
96 {
97 zlib = 0;
98 }

## ◆ ~Zlib_Compression()

Botan::Zlib_Compression::~Zlib_Compression | ( |  | ) |
| inline

Definition at line 39 of file zlib.h.

39 { clear(); }

## Member Function Documentation

## ◆ attachable()

virtual bool Botan::Filter::attachable | ( |  | ) |
| inline virtual inherited

Check whether this filter is an attachable filter.

Returns
  true if this filter is attachable, false otherwise

Reimplemented in Botan::SecureQueue, and Botan::DataSink.

Definition at line 50 of file filter.h.

50 { return true; }

## ◆ end_msg()

void Botan::Zlib_Compression::end_msg | ( |  | ) |
| virtual

Notify that the current message is finished; flush buffers and do end-of-message processing (if any).

Reimplemented from Botan::Filter.

Definition at line 131 of file zlib.cpp.

References Botan::MemoryRegion< T >::begin(), Botan::Filter::send(), and Botan::MemoryRegion< T >::size().

132 {
133 zlib->stream.next_in = 0;
134 zlib->stream.avail_in = 0;
135
136 int rc = Z_OK;
137 while(rc != Z_STREAM_END)
138 {
139 zlib->stream.next_out = reinterpret_cast<Bytef*>(buffer.begin());
140 zlib->stream.avail_out = buffer.size();
141
142 rc = deflate(&(zlib->stream), Z_FINISH);
143 send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
144 }
145
146 clear();
147 }
Botan::Filter::send
void send(const byte in[], size_t length)
Definition: filter.cpp:28
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::MemoryRegion::begin
T * begin()
Definition: secmem.h:59

## ◆ flush()

void Botan::Zlib_Compression::flush | ( |  | ) |

Flush the compressor

Definition at line 152 of file zlib.cpp.

References Botan::MemoryRegion< T >::begin(), Botan::Filter::send(), and Botan::MemoryRegion< T >::size().

153 {
154 zlib->stream.next_in = 0;
155 zlib->stream.avail_in = 0;
156
157 while(true)
158 {
159 zlib->stream.avail_out = buffer.size();
160 zlib->stream.next_out = reinterpret_cast<Bytef*>(buffer.begin());
161
162 deflate(&(zlib->stream), Z_FULL_FLUSH);
163 send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
164
165 if(zlib->stream.avail_out == buffer.size())
166 break;
167 }
168 }
Botan::Filter::send
void send(const byte in[], size_t length)
Definition: filter.cpp:28
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::MemoryRegion::begin
T * begin()
Definition: secmem.h:59

## ◆ name()

std::string Botan::Zlib_Compression::name | ( |  | ) | const
| inline virtual

Returns
  descriptive name for this filter

Implements Botan::Filter.

Definition at line 22 of file zlib.h.

22 { return "Zlib_Compression"; }

## ◆ send() [1/4]

void Botan::Filter::send | ( | const byte | in[],
|  | size_t | length
| ) |  |
| protected inherited

Parameters

  in | some input for the filter
  length | the length of in

Definition at line 28 of file filter.cpp.

References Botan::MemoryRegion< T >::clear(), Botan::MemoryRegion< T >::size(), and Botan::Filter::write().

Referenced by Botan::PK_Encryptor_Filter::end_msg(), end_msg(), Botan::Bzip_Compression::end_msg(), Botan::Hex_Encoder::end_msg(), Botan::Base64_Encoder::end_msg(), Botan::PK_Decryptor_Filter::end_msg(), Botan::Bzip_Decompression::end_msg(), Botan::Zlib_Decompression::end_msg(), Botan::PK_Signer_Filter::end_msg(), Botan::Hex_Decoder::end_msg(), Botan::Base64_Decoder::end_msg(), Botan::PK_Verifier_Filter::end_msg(), Botan::Hash_Filter::end_msg(), Botan::MAC_Filter::end_msg(), Botan::Bzip_Compression::flush(), flush(), write(), Botan::Bzip_Compression::write(), Botan::StreamCipher_Filter::write(), Botan::Bzip_Decompression::write(), Botan::Zlib_Decompression::write(), Botan::Hex_Decoder::write(), and Botan::Base64_Decoder::write().

29 {
30 bool nothing_attached = true;
31 for(size_t j = 0; j != total_ports(); ++j)
32 if(next[j])
33 {
34 if(write_queue.size())
35 next[j]->write(&write_queue[0], write_queue.size());
36 next[j]->write(input, length);
37 nothing_attached = false;
38 }
39
40 if(nothing_attached)
41 write_queue += std::make_pair(input, length);
42 else
43 write_queue.clear();
44 }
Botan::Filter::write
virtual void write(const byte input[], size_t length)=0
Botan::MemoryRegion::clear
void clear()
Definition: secmem.h:158
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ send() [2/4]

void Botan::Filter::send | ( | byte | in | ) |
| inline protected inherited

Parameters

  in | some input for the filter

Definition at line 63 of file filter.h.

References Botan::Filter::send().

Referenced by Botan::Filter::send().

63 { send(&in, 1); }
Botan::Filter::send
void send(const byte in[], size_t length)
Definition: filter.cpp:28

## ◆ send() [3/4]

void Botan::Filter::send | ( | const MemoryRegion< byte > & | in | ) |
| inline protected inherited

Parameters

  in | some input for the filter

Definition at line 68 of file filter.h.

References Botan::Filter::send(), and Botan::MemoryRegion< T >::size().

Referenced by Botan::Filter::send().

68 { send(&in[0], in.size()); }
Botan::Filter::send
void send(const byte in[], size_t length)
Definition: filter.cpp:28
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ send() [4/4]

void Botan::Filter::send | ( | const MemoryRegion< byte > & | in,
|  | size_t | length
| ) |  |
| inline protected inherited

Parameters

  in | some input for the filter
  length | the number of bytes of in to send

Definition at line 74 of file filter.h.

75 {
76 send(&in[0], length);
77 }
Botan::Filter::send
void send(const byte in[], size_t length)
Definition: filter.cpp:28

## ◆ start_msg()

void Botan::Zlib_Compression::start_msg | ( |  | ) |
| virtual

Start a new message. Must be closed by end_msg() before another message can be started.

Reimplemented from Botan::Filter.

Definition at line 103 of file zlib.cpp.

104 {
105 clear();
106 zlib = new Zlib_Stream;
107 if(deflateInit(&(zlib->stream), level) != Z_OK)
108 throw Memory_Exhaustion();
109 }

## ◆ write()

void Botan::Zlib_Compression::write | ( | const byte | input[],
|  | size_t | length
| ) |  |
| virtual

Write a portion of a message to this filter.

Parameters

  input | the input as a byte array
  length | the length of the byte array input

Implements Botan::Filter.

Definition at line 114 of file zlib.cpp.

References Botan::MemoryRegion< T >::begin(), Botan::Filter::send(), and Botan::MemoryRegion< T >::size().

115 {
116 zlib->stream.next_in = static_cast<Bytef*>(const_cast<byte*>(input));
117 zlib->stream.avail_in = length;
118
119 while(zlib->stream.avail_in != 0)
120 {
121 zlib->stream.next_out = static_cast<Bytef*>(buffer.begin());
122 zlib->stream.avail_out = buffer.size();
123 deflate(&(zlib->stream), Z_NO_FLUSH);
124 send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
125 }
126 }
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::Filter::send
void send(const byte in[], size_t length)
Definition: filter.cpp:28
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::MemoryRegion::begin
T * begin()
Definition: secmem.h:59

The documentation for this class was generated from the following files:

- src/filters/zlib/zlib.h
- src/filters/zlib/zlib.cpp