diff options
author | lloyd <[email protected]> | 2015-01-11 03:09:52 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2015-01-11 03:09:52 +0000 |
commit | ac5aae3fa32b51ac38cbbeb0f09116c1f258b9e1 (patch) | |
tree | ffb418e0eae4bc64c94030ef612356f8cecf4210 /src | |
parent | e330e8d66faa0faa0c427acbb7ce42eefe06bd08 (diff) |
Clean up base64 handling. Github pull 40 from webmaster128
Diffstat (limited to 'src')
-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); } |