diff options
author | lloyd <[email protected]> | 2015-01-08 00:31:59 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-01-08 00:31:59 +0000 |
commit | a205bc8691df95b58e651fdb932d886f4f937cb9 (patch) | |
tree | ce4cfa2abf9d0783be4d7717f48c297a41f056f5 /src/lib/codec | |
parent | 281e0276d08a9c6449d869e500150cd92d5759e2 (diff) |
Handle zero length inputs correctly in base64. Github issue 37
Diffstat (limited to 'src/lib/codec')
-rw-r--r-- | src/lib/codec/base64/base64.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/lib/codec/base64/base64.cpp b/src/lib/codec/base64/base64.cpp index 23c60fb35..284ae56f2 100644 --- a/src/lib/codec/base64/base64.cpp +++ b/src/lib/codec/base64/base64.cpp @@ -1,6 +1,6 @@ /* * Base64 Encoding and Decoding -* (C) 2010 Jack Lloyd +* (C) 2010,2015 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -78,7 +78,11 @@ size_t base64_encode(char out[], std::string base64_encode(const byte input[], size_t input_length) { - std::string output((round_up<size_t>(input_length, 3) / 3) * 4, 0); + if(input_length == 0) + return ""; + + const size_t output_length = (round_up<size_t>(input_length, 3) / 3) * 4; + std::string output(output_length, 0); size_t consumed = 0; size_t produced = base64_encode(&output[0], @@ -224,6 +228,9 @@ 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); size_t written = base64_decode(&bin[0], |