From b8a8bcc7e09095360ba4ec7e00e077b040b9d719 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 20 Sep 2026 10:03:32 -0400 Subject: [PATCH] constexpr Base64EncodingBufferSize for C++23 --- libi2pd/Base.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/libi2pd/Base.h b/libi2pd/Base.h index 34531067..ef1a457c 100644 --- a/libi2pd/Base.h +++ b/libi2pd/Base.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2013-2025, The PurpleI2P Project +* Copyright (c) 2013-2026, The PurpleI2P Project * * This file is part of Purple i2pd project and licensed under BSD3 * @@ -14,9 +14,9 @@ #include #include -namespace i2p +namespace i2p { -namespace data +namespace data { std::string ByteStreamToBase64 (const uint8_t * InBuffer, size_t InCount); size_t Base64ToByteStream (std::string_view base64Str, uint8_t * OutBuffer, size_t len); @@ -26,26 +26,30 @@ namespace data constexpr bool IsBase64 (char ch) { return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9') || ch == '-' || ch == '~'; - } + } size_t Base32ToByteStream (std::string_view base32Str, uint8_t * outBuf, size_t outLen); - std::string ByteStreamToBase32 (const uint8_t * inBuf, size_t len); + std::string ByteStreamToBase32 (const uint8_t * inBuf, size_t len); constexpr bool IsBase32 (char ch) { return (ch >= 'a' && ch <= 'z') || (ch >= '2' && ch <= '7'); - } + } /** * Compute the size for a buffer to contain encoded base64 given that the size of the input is input_size bytes */ +#if __cplusplus >= 202302L // C++23 + constexpr size_t Base64EncodingBufferSize(size_t input_size) +#else inline size_t Base64EncodingBufferSize(size_t input_size) +#endif { auto d = std::div (input_size, 3); if (d.rem) d.quot++; return 4 * d.quot; - } + } + - } // data } // i2p