From 02e69f5757be33697ea56ce39ded58d286565507 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 21 Oct 2023 11:41:35 +0100 Subject: [PATCH] Added padding flag --- include/etl/base64.h | 22 ++++++++++++++++++---- test/test_base64_RFC4648_with_padding.cpp | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/etl/base64.h b/include/etl/base64.h index a251051d..69a17359 100644 --- a/include/etl/base64.h +++ b/include/etl/base64.h @@ -80,6 +80,15 @@ namespace etl { public: + //************************************************************************* + /// Default constructor + //************************************************************************* + ETL_CONSTEXPR14 + base64() + : use_padding(true) + { + } + //************************************************************************* /// Encode to Base64 /// Four parameter @@ -599,11 +608,14 @@ namespace etl } } - // Pad out the end of the output buffer. - while (output_count != output_length) + if (use_padding) { - *output++ = padding(); - ++output_count; + // Pad out the end of the output buffer. + while (output_count != output_length) + { + *output++ = padding(); + ++output_count; + } } return output_length; @@ -658,6 +670,8 @@ namespace etl return output_length; } + + bool use_padding; }; } diff --git a/test/test_base64_RFC4648_with_padding.cpp b/test/test_base64_RFC4648_with_padding.cpp index e4cbdafa..8ab90c2b 100644 --- a/test/test_base64_RFC4648_with_padding.cpp +++ b/test/test_base64_RFC4648_with_padding.cpp @@ -563,7 +563,7 @@ namespace etl::array output{ 0 }; b64.encode(input.begin(), Size, - output._buffer, encoded_size); + output._buffer, encoded_size); return output; }