From 899a9d57b3ab310bcee4c5390d706073c77e4514 Mon Sep 17 00:00:00 2001 From: Lars Viklund Date: Thu, 28 Mar 2024 19:06:07 +0100 Subject: [PATCH 1/2] feat: update vcpkg and deps to around 2023-03-02 This updates the following direct dependencies: * curl 8.2.1 -> 8.6.0 * fmt 10.1.1 -> 10.2.1 * giflib 5.2.1 -> removed * glfw3 3.3.8 -> 3.4 * libjpeg-turbo 3.0.0 -> removed * liblzma 5.4.3 -> removed * libpng 1.6.39 -> removed * libsodium 1.0.18 -> removed * zlib 1.3 -> 1.3.1 We cannot track anything newer at the moment as the next commit makes pkg-config run out of resources while validating Abseil packaging. See https://github.com/microsoft/vcpkg/issues/37213 for more information. libsodium replaced with a vendored and modified copy of curl's `curl_base64.h` and `base64.c`. --- CMakeLists.txt | 7 +- LICENSE | 82 ------------ engine/common/base64.c | 277 +++++++++++++++++++++++++++++++++++++++ engine/common/base64.h | 43 ++++++ engine/render/r_main.cpp | 11 +- vcpkg | 2 +- vcpkg-configuration.json | 2 +- vcpkg.json | 5 - 8 files changed, 332 insertions(+), 97 deletions(-) create mode 100644 engine/common/base64.c create mode 100644 engine/common/base64.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 373faa5..e9aa804 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,8 +25,10 @@ set(SIMPLEGRAPHIC_SOURCES "dep/stb/stb_image.h" "dep/stb/stb_image_resize.h" "dep/stb/stb_image_write.h" - "engine/common/common.cpp" "engine/common.h" + "engine/common/base64.c" + "engine/common/base64.h" + "engine/common/common.cpp" "engine/common/console.cpp" "engine/common/console.h" "engine/common/keylist.h" @@ -107,7 +109,6 @@ find_package(fmt CONFIG REQUIRED) find_package(glfw3 CONFIG REQUIRED) find_package(LuaJIT REQUIRED) find_package(re2 CONFIG REQUIRED) -find_package(unofficial-sodium CONFIG REQUIRED) find_package(Threads REQUIRED) find_package(ZLIB REQUIRED) @@ -151,7 +152,6 @@ target_include_directories(SimpleGraphic PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/dep/glad/include ${CMAKE_CURRENT_SOURCE_DIR}/dep/stb - ${JPEG_INCLUDE_DIR} ) if (CMAKE_SYSTEM_NAME MATCHES "Linux") @@ -188,7 +188,6 @@ target_link_libraries(SimpleGraphic imgui LuaJIT::LuaJIT re2::re2 - unofficial-sodium::sodium Threads::Threads ZLIB::ZLIB ) diff --git a/LICENSE b/LICENSE index 4930926..39b2c01 100644 --- a/LICENSE +++ b/LICENSE @@ -175,29 +175,6 @@ without including the above copyright and permission notices. ******************************************************************************* -libsodium: - -******************************************************************************* - -ISC License - -Copyright (c) 2013-2024 -Frank Denis - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -******************************************+++++++++++++++++++++++************** - re2: ******************************************************************************* @@ -478,62 +455,3 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************* - -libjpeg-turbo: - -******************************************************************************* - -Copyright (C)2009-2019 D. R. Commander. All Rights Reserved. -Copyright (C)2015 Viktor Szathmáry. All Rights Reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -- Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. -- Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. -- Neither the name of the libjpeg-turbo Project nor the names of its - contributors may be used to endorse or promote products derived from this - software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -******************************************************************************* - -GIFLIB: - -******************************************************************************* - -The GIFLIB distribution is Copyright (c) 1997 Eric S. Raymond - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -******************************************************************************* diff --git a/engine/common/base64.c b/engine/common/base64.c new file mode 100644 index 0000000..b754e45 --- /dev/null +++ b/engine/common/base64.c @@ -0,0 +1,277 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ + +// Modified for standalone inclusion in SimpleGraphic. + + /* Base64 encoding/decoding */ + +#include "base64.h" + +#include + +/* ---- Base64 Encoding/Decoding Table --- */ +/* Padding character string starts at offset 64. */ +static const char base64encdec[] = +"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + +/* The Base 64 encoding with a URL and filename safe alphabet, RFC 4648 + section 5 */ +static const char base64url[] = +"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; + +static const unsigned char decodetable[] = +{ 62, 255, 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, + 255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51 }; +/* + * Base64Decode() née Curl_base64_decode() + * + * Given a base64 NUL-terminated string at src, decode it and return a + * pointer in *outptr to a newly allocated memory area holding decoded + * data. Size of decoded data is returned in variable pointed by outlen. + * + * Returns CURLE_OK on success, otherwise specific error code. Function + * output shall not be considered valid unless CURLE_OK is returned. + * + * When decoded data length is 0, returns NULL in *outptr. + * + * @unittest: 1302 + */ +bool Base64Decode(const char* src, unsigned char** outptr, size_t* outlen) +{ + size_t srclen = 0; + size_t padding = 0; + size_t i; + size_t numQuantums; + size_t fullQuantums; + size_t rawlen = 0; + unsigned char* pos; + unsigned char* newstr; + unsigned char lookup[256]; + + *outptr = NULL; + *outlen = 0; + srclen = strlen(src); + + /* Check the length of the input string is valid */ + if (!srclen || srclen % 4) + return false; + + /* srclen is at least 4 here */ + while (src[srclen - 1 - padding] == '=') { + /* count padding characters */ + padding++; + /* A maximum of two = padding characters is allowed */ + if (padding > 2) + return false; + } + + /* Calculate the number of quantums */ + numQuantums = srclen / 4; + fullQuantums = numQuantums - (padding ? 1 : 0); + + /* Calculate the size of the decoded string */ + rawlen = (numQuantums * 3) - padding; + + /* Allocate our buffer including room for a null-terminator */ + newstr = malloc(rawlen + 1); + if (!newstr) + return false; + + pos = newstr; + + memset(lookup, 0xff, sizeof(lookup)); + memcpy(&lookup['+'], decodetable, sizeof(decodetable)); + /* replaces + { + unsigned char c; + const unsigned char *p = (const unsigned char *)base64encdec; + for(c = 0; *p; c++, p++) + lookup[*p] = c; + } + */ + + /* Decode the complete quantums first */ + for (i = 0; i < fullQuantums; i++) { + unsigned char val; + unsigned int x = 0; + int j; + + for (j = 0; j < 4; j++) { + val = lookup[(unsigned char)*src++]; + if (val == 0xff) /* bad symbol */ + goto bad; + x = (x << 6) | val; + } + pos[2] = x & 0xff; + pos[1] = (x >> 8) & 0xff; + pos[0] = (x >> 16) & 0xff; + pos += 3; + } + if (padding) { + /* this means either 8 or 16 bits output */ + unsigned char val; + unsigned int x = 0; + int j; + size_t padc = 0; + for (j = 0; j < 4; j++) { + if (*src == '=') { + x <<= 6; + src++; + if (++padc > padding) + /* this is a badly placed '=' symbol! */ + goto bad; + } + else { + val = lookup[(unsigned char)*src++]; + if (val == 0xff) /* bad symbol */ + goto bad; + x = (x << 6) | val; + } + } + if (padding == 1) + pos[1] = (x >> 8) & 0xff; + pos[0] = (x >> 16) & 0xff; + pos += 3 - padding; + } + + /* Zero terminate */ + *pos = '\0'; + + /* Return the decoded data */ + *outptr = newstr; + *outlen = rawlen; + + return true; +bad: + free(newstr); + return false; +} + +static bool base64_encode(const char* table64, + const char* inputbuff, size_t insize, + char** outptr, size_t* outlen) +{ + char* output; + char* base64data; + const unsigned char* in = (unsigned char*)inputbuff; + const char* padstr = &table64[64]; /* Point to padding string. */ + + *outptr = NULL; + *outlen = 0; + + if (!insize) + insize = strlen(inputbuff); + +#if SIZEOF_SIZE_T == 4 + if (insize > UINT_MAX / 4) + return false; +#endif + + base64data = output = malloc((insize + 2) / 3 * 4 + 1); + if (!output) + return false; + + while (insize >= 3) { + *output++ = table64[in[0] >> 2]; + *output++ = table64[((in[0] & 0x03) << 4) | (in[1] >> 4)]; + *output++ = table64[((in[1] & 0x0F) << 2) | ((in[2] & 0xC0) >> 6)]; + *output++ = table64[in[2] & 0x3F]; + insize -= 3; + in += 3; + } + if (insize) { + /* this is only one or two bytes now */ + *output++ = table64[in[0] >> 2]; + if (insize == 1) { + *output++ = table64[((in[0] & 0x03) << 4)]; + if (*padstr) { + *output++ = *padstr; + *output++ = *padstr; + } + } + else { + /* insize == 2 */ + *output++ = table64[((in[0] & 0x03) << 4) | ((in[1] & 0xF0) >> 4)]; + *output++ = table64[((in[1] & 0x0F) << 2)]; + if (*padstr) + *output++ = *padstr; + } + } + + /* Zero terminate */ + *output = '\0'; + + /* Return the pointer to the new data (allocated memory) */ + *outptr = base64data; + + /* Return the length of the new data */ + *outlen = output - base64data; + + return true; +} + +/* + * Base64Encode() née Curl_base64_encode() + * + * Given a pointer to an input buffer and an input size, encode it and + * return a pointer in *outptr to a newly allocated memory area holding + * encoded data. Size of encoded data is returned in variable pointed by + * outlen. + * + * Input length of 0 indicates input buffer holds a NUL-terminated string. + * + * Returns CURLE_OK on success, otherwise specific error code. Function + * output shall not be considered valid unless CURLE_OK is returned. + * + * @unittest: 1302 + */ +bool Base64Encode(const char* inputbuff, size_t insize, + char** outptr, size_t* outlen) +{ + return base64_encode(base64encdec, inputbuff, insize, outptr, outlen); +} + +/* + * Base64UrlEncode() née Curl_base64url_encode() + * + * Given a pointer to an input buffer and an input size, encode it and + * return a pointer in *outptr to a newly allocated memory area holding + * encoded data. Size of encoded data is returned in variable pointed by + * outlen. + * + * Input length of 0 indicates input buffer holds a NUL-terminated string. + * + * Returns CURLE_OK on success, otherwise specific error code. Function + * output shall not be considered valid unless CURLE_OK is returned. + * + * @unittest: 1302 + */ +bool Base64UrlEncode(const char* inputbuff, size_t insize, + char** outptr, size_t* outlen) +{ + return base64_encode(base64url, inputbuff, insize, outptr, outlen); +} diff --git a/engine/common/base64.h b/engine/common/base64.h new file mode 100644 index 0000000..e637be4 --- /dev/null +++ b/engine/common/base64.h @@ -0,0 +1,43 @@ +#pragma once +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ + +// Modified for standalone inclusion in SimpleGraphic. + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +bool Base64Encode(const char* inputbuff, size_t insize, + char** outptr, size_t* outlen); +bool Base64UrlEncode(const char* inputbuff, size_t insize, + char** outptr, size_t* outlen); +bool Base64Decode(const char* src, + unsigned char** outptr, size_t* outlen); + +#ifdef __cplusplus +} +#endif diff --git a/engine/render/r_main.cpp b/engine/render/r_main.cpp index c399c25..ca80d57 100644 --- a/engine/render/r_main.cpp +++ b/engine/render/r_main.cpp @@ -8,6 +8,8 @@ #define IMGUI_DEFINE_MATH_OPERATORS #include "r_local.h" +#include "common/base64.h" + #include #include #include @@ -16,7 +18,6 @@ #include #include #include -#include #include #include @@ -1454,9 +1455,11 @@ void r_renderer_c::EndFrame() if (showHash) { if (ImGui::Begin("Hash")) { - std::vector b64(sodium_base64_ENCODED_LEN(lastFrameHash.size(), sodium_base64_VARIANT_URLSAFE)); - sodium_bin2base64(b64.data(), b64.size(), lastFrameHash.data(), lastFrameHash.size(), sodium_base64_VARIANT_URLSAFE); - ImGui::Text("%s", b64.data()); + char* b64{}; + size_t b64Len{}; + Base64UrlEncode((char const*)lastFrameHash.data(), lastFrameHash.size(), &b64, &b64Len); + ImGui::Text("%s", b64); + free(b64); } ImGui::End(); } diff --git a/vcpkg b/vcpkg index 4cfabe7..836a2d6 160000 --- a/vcpkg +++ b/vcpkg @@ -1 +1 @@ -Subproject commit 4cfabe769eaceb209ea37267e8c50c43b86a4a7b +Subproject commit 836a2d684dac6b543563e53ab30a1a5b8afaf97b diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json index fc08bde..faed024 100644 --- a/vcpkg-configuration.json +++ b/vcpkg-configuration.json @@ -1,7 +1,7 @@ { "default-registry": { "kind": "builtin", - "baseline": "4cfabe769eaceb209ea37267e8c50c43b86a4a7b" + "baseline": "836a2d684dac6b543563e53ab30a1a5b8afaf97b" }, "registries": [ { diff --git a/vcpkg.json b/vcpkg.json index 6d724f0..035135a 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -5,12 +5,7 @@ "angle", "curl", "fmt", - "giflib", "glfw3", - "libjpeg-turbo", - "liblzma", - "libpng", - "libsodium", "luajit", "pkgconf", "re2", From 0d25b182a34aeb749d0abb07a77a9c4e41fd4ac5 Mon Sep 17 00:00:00 2001 From: Wires77 Date: Fri, 29 Mar 2024 01:41:34 -0500 Subject: [PATCH 2/2] Add curl copyright to LICENSE file --- LICENSE | 29 +++++++++++++++++++++++++++++ engine/common/base64.c | 4 ++-- engine/common/base64.h | 4 ++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index 39b2c01..641f766 100644 --- a/LICENSE +++ b/LICENSE @@ -393,6 +393,35 @@ END OF TERMS AND CONDITIONS ******************************************************************************* +curl: + +******************************************************************************* + +COPYRIGHT AND PERMISSION NOTICE + +Copyright (c) 1996 - 2024, Daniel Stenberg, , and many +contributors, see the THANKS file. + +All rights reserved. + +Permission to use, copy, modify, and distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright +notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of a copyright holder shall not +be used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization of the copyright holder. + +******************************************************************************* + ANGLE: ******************************************************************************* diff --git a/engine/common/base64.c b/engine/common/base64.c index b754e45..c02a2b6 100644 --- a/engine/common/base64.c +++ b/engine/common/base64.c @@ -7,13 +7,13 @@ * * Copyright (C) Daniel Stenberg, , et al. * - * This software is licensed as described in the file COPYING, which + * This software is licensed as described in the file LICENSE, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. + * furnished to do so, under the terms of the LICENSE file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. diff --git a/engine/common/base64.h b/engine/common/base64.h index e637be4..5cb097f 100644 --- a/engine/common/base64.h +++ b/engine/common/base64.h @@ -8,13 +8,13 @@ * * Copyright (C) Daniel Stenberg, , et al. * - * This software is licensed as described in the file COPYING, which + * This software is licensed as described in the file LICENSE, which * you should have received as part of this distribution. The terms * are also available at https://curl.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the COPYING file. + * furnished to do so, under the terms of the LICENSE file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied.