moonchen commented on a change in pull request #8736:
URL: https://github.com/apache/trafficserver/pull/8736#discussion_r833460273
##########
File path: include/tscore/ink_base64.h
##########
@@ -42,5 +42,16 @@ bool ats_base64_encode(const unsigned char *inBuffer, size_t
inBufferSize, char
bool ats_base64_decode(const char *inBuffer, size_t inBufferSize, unsigned
char *outBuffer, size_t outBufSize, size_t *length);
// Little helper functions to calculate minimum required output buffer for
encoding/decoding.
-#define ATS_BASE64_ENCODE_DSTLEN(_length) ((_length * 8) / 6 + 4)
-#define ATS_BASE64_DECODE_DSTLEN(_length) (((_length + 3) / 4) * 3)
+// These sizes include one byte for null termination, because
ats_base64_encode and ats_base64_decode will always write a null
+// terminator.
+inline constexpr size_t
+ats_base64_encode_dstlen(size_t length)
+{
+ return ((length + 2) / 3) * 4 + 1;
+}
+
+inline constexpr size_t
+ats_base64_decode_dstlen(size_t length)
+{
+ return ((length + 3) / 4) * 3 + 1;
+}
Review comment:
The length calculation is meant for `ats_base64_encode()`, so the goal
is to just give the length of the buffer needed to store the encoded output.
Both `ats_base64_encode()` and the
[RFC](https://datatracker.ietf.org/doc/html/rfc4648#section-4) specify padding
that is non-optional.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]