From ac5aae3fa32b51ac38cbbeb0f09116c1f258b9e1 Mon Sep 17 00:00:00 2001 From: lloyd Date: Sun, 11 Jan 2015 03:09:52 +0000 Subject: Clean up base64 handling. Github pull 40 from webmaster128 --- src/lib/codec/base64/base64.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/lib/codec/base64/base64.cpp b/src/lib/codec/base64/base64.cpp index 9e463e680..aaf04d9d2 100644 --- a/src/lib/codec/base64/base64.cpp +++ b/src/lib/codec/base64/base64.cpp @@ -78,10 +78,9 @@ size_t base64_encode(char out[], std::string base64_encode(const byte input[], size_t input_length) { - if(input_length == 0) - return ""; - - const size_t output_length = (round_up(input_length, 3) / 3) * 4; + const size_t output_length = (input_length == 0) + ? 0 + : (round_up(input_length, 3) / 3) * 4; std::string output(output_length, 0); size_t consumed = 0; @@ -221,17 +220,17 @@ size_t base64_decode(byte output[], const std::string& input, bool ignore_ws) { - return base64_decode(output, &input[0], input.length(), ignore_ws); + return base64_decode(output, input.data(), input.length(), ignore_ws); } secure_vector base64_decode(const char input[], size_t input_length, bool ignore_ws) - { - if(input_length == 0) - return secure_vector(); - - secure_vector bin((round_up(input_length, 4) * 3) / 4); + { + const size_t output_length = (input_length == 0) + ? 0 + : (round_up(input_length, 4) * 3) / 4; + secure_vector bin(output_length); size_t written = base64_decode(&bin[0], input, @@ -245,7 +244,7 @@ secure_vector base64_decode(const char input[], secure_vector base64_decode(const std::string& input, bool ignore_ws) { - return base64_decode(&input[0], input.size(), ignore_ws); + return base64_decode(input.data(), input.size(), ignore_ws); } -- cgit v1.2.3