aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/codec/base64/base64.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/codec/base64/base64.cpp')
-rw-r--r--src/lib/codec/base64/base64.cpp43
1 files changed, 8 insertions, 35 deletions
diff --git a/src/lib/codec/base64/base64.cpp b/src/lib/codec/base64/base64.cpp
index 1f7937727..b4f78bca0 100644
--- a/src/lib/codec/base64/base64.cpp
+++ b/src/lib/codec/base64/base64.cpp
@@ -17,6 +17,11 @@ namespace {
class Base64 final
{
public:
+ static inline std::string name() noexcept
+ {
+ return "base64";
+ }
+
static inline size_t encoding_bytes_in() noexcept
{
return m_encoding_bytes_in;
@@ -170,23 +175,7 @@ size_t base64_encode(char out[],
std::string base64_encode(const uint8_t input[],
size_t input_length)
{
- const size_t output_length = Base64::encode_max_output(input_length);
- std::string output(output_length, 0);
-
- size_t consumed = 0;
- size_t produced = 0;
-
- if(output_length > 0)
- {
- produced = base64_encode(&output.front(),
- input, input_length,
- consumed, true);
- }
-
- BOTAN_ASSERT_EQUAL(consumed, input_length, "Consumed the entire input");
- BOTAN_ASSERT_EQUAL(produced, output.size(), "Produced expected size");
-
- return output;
+ return base_encode_to_string(Base64(), input, input_length);
}
size_t base64_decode(uint8_t out[],
@@ -204,14 +193,7 @@ size_t base64_decode(uint8_t output[],
size_t input_length,
bool ignore_ws)
{
- size_t consumed = 0;
- size_t written = base64_decode(output, input, input_length,
- consumed, true, ignore_ws);
-
- if(consumed != input_length)
- { throw Invalid_Argument("base64_decode: input did not have full bytes"); }
-
- return written;
+ return base_decode_full(Base64(), output, input, input_length, ignore_ws);
}
size_t base64_decode(uint8_t output[],
@@ -225,16 +207,7 @@ secure_vector<uint8_t> base64_decode(const char input[],
size_t input_length,
bool ignore_ws)
{
- const size_t output_length = Base64::decode_max_output(input_length);
- secure_vector<uint8_t> bin(output_length);
-
- size_t written = base64_decode(bin.data(),
- input,
- input_length,
- ignore_ws);
-
- bin.resize(written);
- return bin;
+ return base_decode_to_vec<secure_vector<uint8_t>>(Base64(), input, input_length, ignore_ws);
}
secure_vector<uint8_t> base64_decode(const std::string& input,