Botan 3.0.0-alpha0
Crypto and TLS for C&
compression.cpp
Go to the documentation of this file.
1/*
2* Compression Factory
3* (C) 2014,2016 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/compression.h>
9#include <botan/mem_ops.h>
10#include <botan/exceptn.h>
11#include <cstdlib>
12
13#if defined(BOTAN_HAS_ZLIB)
14 #include <botan/zlib.h>
15#endif
16
17#if defined(BOTAN_HAS_BZIP2)
18 #include <botan/bzip2.h>
19#endif
20
21#if defined(BOTAN_HAS_LZMA)
22 #include <botan/lzma.h>
23#endif
24
25namespace Botan {
26
27//static
28std::unique_ptr<Compression_Algorithm>
30 {
31#if defined(BOTAN_HAS_ZLIB)
32 if(name == "Zlib" || name == "zlib")
33 return std::make_unique<Zlib_Compression>();
34 if(name == "Gzip" || name == "gzip" || name == "gz")
35 return std::make_unique<Gzip_Compression>();
36 if(name == "Deflate" || name == "deflate")
37 return std::make_unique<Deflate_Compression>();
38#endif
39
40#if defined(BOTAN_HAS_BZIP2)
41 if(name == "bzip2" || name == "bz2" || name == "Bzip2")
42 return std::make_unique<Bzip2_Compression>();
43#endif
44
45#if defined(BOTAN_HAS_LZMA)
46 if(name == "lzma" || name == "xz" || name == "LZMA")
47 return std::make_unique<LZMA_Compression>();
48#endif
49
51 return nullptr;
52 }
53
54//static
55std::unique_ptr<Compression_Algorithm>
57 {
58 if(auto compressor = Compression_Algorithm::create(algo))
59 {
60 return compressor;
61 }
62 throw Lookup_Error("Compression", algo, "");
63 }
64
65//static
66std::unique_ptr<Decompression_Algorithm>
68 {
69#if defined(BOTAN_HAS_ZLIB)
70 if(name == "Zlib" || name == "zlib")
71 return std::make_unique<Zlib_Decompression>();
72 if(name == "Gzip" || name == "gzip" || name == "gz")
73 return std::make_unique<Gzip_Decompression>();
74 if(name == "Deflate" || name == "deflate")
75 return std::make_unique<Deflate_Decompression>();
76#endif
77
78#if defined(BOTAN_HAS_BZIP2)
79 if(name == "bzip2" || name == "bz2" || name == "Bzip2")
80 return std::make_unique<Bzip2_Decompression>();
81#endif
82
83#if defined(BOTAN_HAS_LZMA)
84 if(name == "lzma" || name == "xz" || name == "LZMA")
85 return std::make_unique<LZMA_Decompression>();
86#endif
87
89 return nullptr;
90 }
91
92//static
93std::unique_ptr<Decompression_Algorithm>
95 {
96 if(auto decompressor = Decompression_Algorithm::create(algo))
97 {
98 return decompressor;
99 }
100 throw Lookup_Error("Decompression", algo, "");
101 }
102
103}
104
#define BOTAN_UNUSED(...)
Definition: assert.h:141
static std::unique_ptr< Compression_Algorithm > create(const std::string &algo_spec)
Definition: compression.cpp:29
virtual std::string name() const =0
static std::unique_ptr< Compression_Algorithm > create_or_throw(const std::string &algo_spec)
Definition: compression.cpp:56
static std::unique_ptr< Decompression_Algorithm > create(const std::string &algo_spec)
Definition: compression.cpp:67
static std::unique_ptr< Decompression_Algorithm > create_or_throw(const std::string &algo_spec)
Definition: compression.cpp:94
virtual std::string name() const =0
std::string name
Definition: alg_id.cpp:13