Botan 3.0.0-alpha0
Crypto and TLS for C&
base32.h
Go to the documentation of this file.
1/*
2* Base32 Encoding and Decoding
3* (C) 2018 Erwan Chaussy
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_BASE32_CODEC_H_
9#define BOTAN_BASE32_CODEC_H_
10
11#include <botan/secmem.h>
12#include <string>
13
14namespace Botan {
15
16/**
17* Perform base32 encoding
18* @param output an array of at least base32_encode_max_output bytes
19* @param input is some binary data
20* @param input_length length of input in bytes
21* @param input_consumed is an output parameter which says how many
22* bytes of input were actually consumed. If less than
23* input_length, then the range input[consumed:length]
24* should be passed in later along with more input.
25* @param final_inputs true iff this is the last input, in which case
26 padding chars will be applied if needed
27* @return number of bytes written to output
28*/
29size_t BOTAN_PUBLIC_API(2, 7) base32_encode(char output[],
30 const uint8_t input[],
31 size_t input_length,
32 size_t& input_consumed,
33 bool final_inputs);
34
35/**
36* Perform base32 encoding
37* @param input some input
38* @param input_length length of input in bytes
39* @return base32 representation of input
40*/
41std::string BOTAN_PUBLIC_API(2, 7) base32_encode(const uint8_t input[],
42 size_t input_length);
43
44/**
45* Perform base32 encoding
46* @param input some input
47* @return base32 representation of input
48*/
49template <typename Alloc>
50std::string base32_encode(const std::vector<uint8_t, Alloc>& input)
51 {
52 return base32_encode(input.data(), input.size());
53 }
54
55/**
56* Perform base32 decoding
57* @param output an array of at least base32_decode_max_output bytes
58* @param input some base32 input
59* @param input_length length of input in bytes
60* @param input_consumed is an output parameter which says how many
61* bytes of input were actually consumed. If less than
62* input_length, then the range input[consumed:length]
63* should be passed in later along with more input.
64* @param final_inputs true iff this is the last input, in which case
65 padding is allowed
66* @param ignore_ws ignore whitespace on input; if false, throw an
67 exception if whitespace is encountered
68* @return number of bytes written to output
69*/
70size_t BOTAN_PUBLIC_API(2, 7) base32_decode(uint8_t output[],
71 const char input[],
72 size_t input_length,
73 size_t& input_consumed,
74 bool final_inputs,
75 bool ignore_ws = true);
76
77/**
78* Perform base32 decoding
79* @param output an array of at least base32_decode_max_output bytes
80* @param input some base32 input
81* @param input_length length of input in bytes
82* @param ignore_ws ignore whitespace on input; if false, throw an
83 exception if whitespace is encountered
84* @return number of bytes written to output
85*/
86size_t BOTAN_PUBLIC_API(2, 7) base32_decode(uint8_t output[],
87 const char input[],
88 size_t input_length,
89 bool ignore_ws = true);
90
91/**
92* Perform base32 decoding
93* @param output an array of at least base32_decode_max_output bytes
94* @param input some base32 input
95* @param ignore_ws ignore whitespace on input; if false, throw an
96 exception if whitespace is encountered
97* @return number of bytes written to output
98*/
99size_t BOTAN_PUBLIC_API(2, 7) base32_decode(uint8_t output[],
100 const std::string& input,
101 bool ignore_ws = true);
102
103/**
104* Perform base32 decoding
105* @param input some base32 input
106* @param input_length the length of input in bytes
107* @param ignore_ws ignore whitespace on input; if false, throw an
108 exception if whitespace is encountered
109* @return decoded base32 output
110*/
111secure_vector<uint8_t> BOTAN_PUBLIC_API(2, 7) base32_decode(const char input[],
112 size_t input_length,
113 bool ignore_ws = true);
114
115/**
116* Perform base32 decoding
117* @param input some base32 input
118* @param ignore_ws ignore whitespace on input; if false, throw an
119 exception if whitespace is encountered
120* @return decoded base32 output
121*/
122secure_vector<uint8_t> BOTAN_PUBLIC_API(2, 7) base32_decode(const std::string& input,
123 bool ignore_ws = true);
124
125} // namespace Botan
126
127#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: alg_id.cpp:13
size_t base32_decode(uint8_t out[], const char in[], size_t input_length, size_t &input_consumed, bool final_inputs, bool ignore_ws)
Definition: base32.cpp:195
size_t base32_encode(char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
Definition: base32.cpp:180
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65
Definition: bigint.h:1077