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

#include <zlib.h>

Inheritance diagram for Botan::Zlib_Compression:
Botan::Filter

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, bool raw_deflate=false)
 
 ~Zlib_Compression ()
 

Protected Member Functions

virtual void send (const byte in[], size_t length)
 
void send (byte in)
 
void send (const secure_vector< byte > &in)
 
void send (const std::vector< byte > &in)
 
void send (const secure_vector< byte > &in, size_t length)
 
void send (const std::vector< byte > &in, size_t length)
 

Detailed Description

Zlib Compression Filter

Definition at line 19 of file zlib.h.

Constructor & Destructor Documentation

Botan::Zlib_Compression::Zlib_Compression ( size_t  level = 6,
bool  raw_deflate = false 
)
Parameters
levelhow much effort to use on compressing (0 to 9); higher levels are slower but tend to give better compression
raw_deflateif true no zlib header/trailer will be used

Definition at line 96 of file zlib.cpp.

97  :
98  level((l >= 9) ? 9 : l),
99  raw_deflate(raw_deflate),
100  buffer(DEFAULT_BUFFERSIZE),
101  zlib(0)
102  {
}
Botan::Zlib_Compression::~Zlib_Compression ( )
inline

Definition at line 42 of file zlib.h.

42 { clear(); }

Member Function Documentation

virtual bool Botan::Filter::attachable ( )
inlinevirtualinherited

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 52 of file filter.h.

52 { return true; }
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 145 of file zlib.cpp.

References Botan::Filter::send().

146  {
147  zlib->stream.next_in = 0;
148  zlib->stream.avail_in = 0;
149 
150  int rc = Z_OK;
151  while(rc != Z_STREAM_END)
152  {
153  zlib->stream.next_out = reinterpret_cast<Bytef*>(&buffer[0]);
154  zlib->stream.avail_out = buffer.size();
155 
156  rc = deflate(&(zlib->stream), Z_FINISH);
157  send(&buffer[0], buffer.size() - zlib->stream.avail_out);
158  }
159 
160  clear();
161  }
void Botan::Zlib_Compression::flush ( )

Flush the compressor

Definition at line 166 of file zlib.cpp.

References Botan::Filter::send().

167  {
168  zlib->stream.next_in = 0;
169  zlib->stream.avail_in = 0;
170 
171  while(true)
172  {
173  zlib->stream.avail_out = buffer.size();
174  zlib->stream.next_out = reinterpret_cast<Bytef*>(&buffer[0]);
175 
176  deflate(&(zlib->stream), Z_FULL_FLUSH);
177  send(&buffer[0], buffer.size() - zlib->stream.avail_out);
178 
179  if(zlib->stream.avail_out == buffer.size())
180  break;
181  }
182  }
std::string Botan::Zlib_Compression::name ( ) const
inlinevirtual
Returns
descriptive name for this filter

Implements Botan::Filter.

Definition at line 22 of file zlib.h.

22 { return "Zlib_Compression"; }
void Botan::Filter::send ( const byte  in[],
size_t  length 
)
protectedvirtualinherited
Parameters
insome input for the filter
lengththe length of in

Reimplemented in Botan::Threaded_Fork.

Definition at line 28 of file filter.cpp.

References Botan::Filter::write().

Referenced by Botan::PK_Encryptor_Filter::end_msg(), end_msg(), Botan::Bzip_Compression::end_msg(), Botan::Lzma_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::PK_Signer_Filter::end_msg(), Botan::Lzma_Decompression::end_msg(), Botan::Zlib_Decompression::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(), Botan::Lzma_Compression::flush(), Botan::Bzip_Compression::write(), write(), Botan::Lzma_Compression::write(), Botan::StreamCipher_Filter::write(), Botan::Bzip_Decompression::write(), Botan::Lzma_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  }
void Botan::Filter::send ( byte  in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 65 of file filter.h.

References Botan::Filter::send().

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

65 { send(&in, 1); }
void Botan::Filter::send ( const secure_vector< byte > &  in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 70 of file filter.h.

References Botan::Filter::send().

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

70 { send(&in[0], in.size()); }
void Botan::Filter::send ( const std::vector< byte > &  in)
inlineprotectedinherited
Parameters
insome input for the filter

Definition at line 75 of file filter.h.

References Botan::Filter::send().

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

75 { send(&in[0], in.size()); }
void Botan::Filter::send ( const secure_vector< byte > &  in,
size_t  length 
)
inlineprotectedinherited
Parameters
insome input for the filter
lengththe number of bytes of in to send

Definition at line 81 of file filter.h.

82  {
83  send(&in[0], length);
84  }
void Botan::Filter::send ( const std::vector< byte > &  in,
size_t  length 
)
inlineprotectedinherited
Parameters
insome input for the filter
lengththe number of bytes of in to send

Definition at line 90 of file filter.h.

91  {
92  send(&in[0], length);
93  }
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 107 of file zlib.cpp.

108  {
109  clear();
110  zlib = new Zlib_Stream;
111 
112  int res = deflateInit2(&(zlib->stream),
113  level,
114  Z_DEFLATED,
115  (raw_deflate ? -15 : 15),
116  8,
117  Z_DEFAULT_STRATEGY);
118 
119  if(res == Z_STREAM_ERROR)
120  throw Invalid_Argument("Bad setting in deflateInit2");
121  else if(res != Z_OK)
122  throw Memory_Exhaustion();
123  }
void Botan::Zlib_Compression::write ( const byte  input[],
size_t  length 
)
virtual

Write a portion of a message to this filter.

Parameters
inputthe input as a byte array
lengththe length of the byte array input

Implements Botan::Filter.

Definition at line 128 of file zlib.cpp.

References Botan::Filter::send().

129  {
130  zlib->stream.next_in = static_cast<Bytef*>(const_cast<byte*>(input));
131  zlib->stream.avail_in = length;
132 
133  while(zlib->stream.avail_in != 0)
134  {
135  zlib->stream.next_out = static_cast<Bytef*>(&buffer[0]);
136  zlib->stream.avail_out = buffer.size();
137  deflate(&(zlib->stream), Z_NO_FLUSH);
138  send(&buffer[0], buffer.size() - zlib->stream.avail_out);
139  }
140  }

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