diff options
-rw-r--r-- | src/lib/codec/base64/base64.cpp | 21 |
1 files 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<size_t>(input_length, 3) / 3) * 4; + const size_t output_length = (input_length == 0) + ? 0 + : (round_up<size_t>(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<byte> base64_decode(const char input[], size_t input_length, bool ignore_ws) - { - if(input_length == 0) - return secure_vector<byte>(); - - secure_vector<byte> bin((round_up<size_t>(input_length, 4) * 3) / 4); + { + const size_t output_length = (input_length == 0) + ? 0 + : (round_up<size_t>(input_length, 4) * 3) / 4; + secure_vector<byte> bin(output_length); size_t written = base64_decode(&bin[0], input, @@ -245,7 +244,7 @@ secure_vector<byte> base64_decode(const char input[], secure_vector<byte> 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); } |