Botan 3.4.0
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 <span>
13#include <string>
14#include <string_view>
15
16namespace Botan {
17
18/**
19* Perform base32 encoding
20* @param output an array of at least base32_encode_max_output bytes
21* @param input is some binary data
22* @param input_length length of input in bytes
23* @param input_consumed is an output parameter which says how many
24* bytes of input were actually consumed. If less than
25* input_length, then the range input[consumed:length]
26* should be passed in later along with more input.
27* @param final_inputs true iff this is the last input, in which case
28 padding chars will be applied if needed
29* @return number of bytes written to output
30*/
31size_t BOTAN_PUBLIC_API(2, 7)
32 base32_encode(char output[], const uint8_t input[], size_t input_length, size_t& input_consumed, bool final_inputs);
33
34/**
35* Perform base32 encoding
36* @param input some input
37* @param input_length length of input in bytes
38* @return base32 representation of input
39*/
40std::string BOTAN_PUBLIC_API(2, 7) base32_encode(const uint8_t input[], size_t input_length);
41
42/**
43* Perform base32 encoding
44* @param input some input
45* @return base32 representation of input
46*/
47inline std::string base32_encode(std::span<const uint8_t> input) {
48 return base32_encode(input.data(), input.size());
49}
50
51/**
52* Perform base32 decoding
53* @param output an array of at least base32_decode_max_output bytes
54* @param input some base32 input
55* @param input_length length of input in bytes
56* @param input_consumed is an output parameter which says how many
57* bytes of input were actually consumed. If less than
58* input_length, then the range input[consumed:length]
59* should be passed in later along with more input.
60* @param final_inputs true iff this is the last input, in which case
61 padding is allowed
62* @param ignore_ws ignore whitespace on input; if false, throw an
63 exception if whitespace is encountered
64* @return number of bytes written to output
65*/
66size_t BOTAN_PUBLIC_API(2, 7) base32_decode(uint8_t output[],
67 const char input[],
68 size_t input_length,
69 size_t& input_consumed,
70 bool final_inputs,
71 bool ignore_ws = true);
72
73/**
74* Perform base32 decoding
75* @param output an array of at least base32_decode_max_output bytes
76* @param input some base32 input
77* @param input_length length of input in bytes
78* @param ignore_ws ignore whitespace on input; if false, throw an
79 exception if whitespace is encountered
80* @return number of bytes written to output
81*/
82size_t BOTAN_PUBLIC_API(2, 7)
83 base32_decode(uint8_t output[], const char input[], size_t input_length, bool ignore_ws = true);
84
85/**
86* Perform base32 decoding
87* @param output an array of at least base32_decode_max_output bytes
88* @param input some base32 input
89* @param ignore_ws ignore whitespace on input; if false, throw an
90 exception if whitespace is encountered
91* @return number of bytes written to output
92*/
93size_t BOTAN_PUBLIC_API(2, 7) base32_decode(uint8_t output[], std::string_view input, bool ignore_ws = true);
94
95/**
96* Perform base32 decoding
97* @param input some base32 input
98* @param input_length the length of input in bytes
99* @param ignore_ws ignore whitespace on input; if false, throw an
100 exception if whitespace is encountered
101* @return decoded base32 output
102*/
103secure_vector<uint8_t> BOTAN_PUBLIC_API(2, 7)
104 base32_decode(const char input[], size_t input_length, bool ignore_ws = true);
105
106/**
107* Perform base32 decoding
108* @param input some base32 input
109* @param ignore_ws ignore whitespace on input; if false, throw an
110 exception if whitespace is encountered
111* @return decoded base32 output
112*/
113secure_vector<uint8_t> BOTAN_PUBLIC_API(2, 7) base32_decode(std::string_view input, bool ignore_ws = true);
114
115} // namespace Botan
116
117#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
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:151
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61
size_t base32_encode(char out[], const uint8_t in[], size_t input_length, size_t &input_consumed, bool final_inputs)
Definition base32.cpp:143