9#include <botan/filters.h>
11#include <botan/exceptn.h>
12#include <botan/internal/fmt.h>
14#if defined(BOTAN_HAS_COMPRESSION)
15 #include <botan/compression.h>
20#if defined(BOTAN_HAS_COMPRESSION)
22Compression_Filter::Compression_Filter(std::string_view type,
size_t level,
size_t bs) :
23 m_comp(Compression_Algorithm::create(type)), m_buffersize(std::max<size_t>(bs, 256)), m_level(level) {
25 throw Invalid_Argument(
fmt(
"Compression type '{}' not found", type));
29Compression_Filter::~Compression_Filter() =
default;
31std::string Compression_Filter::name()
const {
32 return m_comp->name();
35void Compression_Filter::start_msg() {
36 m_comp->start(m_level);
39void Compression_Filter::write(
const uint8_t input[],
size_t input_length) {
41 const size_t take = std::min(m_buffersize, input_length);
44 m_buffer.assign(input, input + take);
45 m_comp->update(m_buffer);
54void Compression_Filter::flush() {
56 m_comp->update(m_buffer, 0,
true);
60void Compression_Filter::end_msg() {
62 m_comp->finish(m_buffer);
66Decompression_Filter::Decompression_Filter(std::string_view type,
size_t bs) :
67 m_comp(Decompression_Algorithm::create(type)), m_buffersize(std::max<size_t>(bs, 256)) {
69 throw Invalid_Argument(
fmt(
"Compression type '{}' not found", type));
73Decompression_Filter::~Decompression_Filter() =
default;
75std::string Decompression_Filter::name()
const {
76 return m_comp->name();
79void Decompression_Filter::start_msg() {
83void Decompression_Filter::write(
const uint8_t input[],
size_t input_length) {
85 const size_t take = std::min(m_buffersize, input_length);
88 m_buffer.assign(input, input + take);
89 m_comp->update(m_buffer);
98void Decompression_Filter::end_msg() {
100 m_comp->finish(m_buffer);
#define BOTAN_ASSERT(expr, assertion_made)
std::string fmt(std::string_view format, const T &... args)