Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package orcania for openSUSE:Factory checked in at 2022-05-30 12:43:59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/orcania (Old) and /work/SRC/openSUSE:Factory/.orcania.new.2254 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "orcania" Mon May 30 12:43:59 2022 rev:11 rq:979714 version:2.3.0 Changes: -------- --- /work/SRC/openSUSE:Factory/orcania/orcania.changes 2022-03-14 19:37:48.782180097 +0100 +++ /work/SRC/openSUSE:Factory/.orcania.new.2254/orcania.changes 2022-05-30 12:44:53.216465317 +0200 @@ -1,0 +2,10 @@ +Sat May 28 16:00:58 UTC 2022 - Martin Hauke <mar...@gmx.de> + +- Update to version 2.3.0 + * Add o_base64_encode_alloc, o_base64_decode_alloc, + o_base64url_encode_alloc, o_base64url_decode_alloc, + o_base64url_2_base64_alloc, o_base64_2_base64url_alloc. + * Fix pkg-config file with absolute path for + CMAKE_INSTALL_{INCLUDE,LIB}DIR. + +------------------------------------------------------------------- Old: ---- orcania-2.2.2.tar.gz New: ---- orcania-2.3.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ orcania.spec ++++++ --- /var/tmp/diff_new_pack.uAXMtZ/_old 2022-05-30 12:44:53.724465993 +0200 +++ /var/tmp/diff_new_pack.uAXMtZ/_new 2022-05-30 12:44:53.728465998 +0200 @@ -2,7 +2,7 @@ # spec file for package orcania # # Copyright (c) 2022 SUSE LLC -# Copyright (c) 2018-2021, Martin Hauke <mar...@gmx.de> +# Copyright (c) 2018-2022, Martin Hauke <mar...@gmx.de> # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,9 +17,9 @@ # -%define sover 2_2 +%define sover 2_3 Name: orcania -Version: 2.2.2 +Version: 2.3.0 Release: 0 Summary: MISC function Library License: LGPL-2.1-or-later ++++++ orcania-2.2.2.tar.gz -> orcania-2.3.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orcania-2.2.2/.gitignore new/orcania-2.3.0/.gitignore --- old/orcania-2.2.2/.gitignore 2022-03-09 22:23:46.000000000 +0100 +++ new/orcania-2.3.0/.gitignore 2022-05-25 16:50:33.000000000 +0200 @@ -4,10 +4,4 @@ *.a *.pc *.log -str_test -split_test -memory_test -pointer_list_test orcania-cfg.h -valgrind*.txt -tools/base64url/base64url diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orcania-2.2.2/CHANGELOG.md new/orcania-2.3.0/CHANGELOG.md --- old/orcania-2.2.2/CHANGELOG.md 2022-03-09 22:23:46.000000000 +0100 +++ new/orcania-2.3.0/CHANGELOG.md 2022-05-25 16:50:33.000000000 +0200 @@ -1,5 +1,10 @@ # Orcania Changelog +## 2.3.0 + +- Add `o_base64_encode_alloc`, `o_base64_decode_alloc`, `o_base64url_encode_alloc`, `o_base64url_decode_alloc`, `o_base64url_2_base64_alloc`, `o_base64_2_base64url_alloc` +- Fix pkg-config file with absolute path for `CMAKE_INSTALL_{INCLUDE,LIB}DIR`, Closes #27 + ## 2.2.2 - Add `o_strnullempty` diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orcania-2.2.2/CMakeLists.txt new/orcania-2.3.0/CMakeLists.txt --- old/orcania-2.2.2/CMakeLists.txt 2022-03-09 22:23:46.000000000 +0100 +++ new/orcania-2.3.0/CMakeLists.txt 2022-05-25 16:50:33.000000000 +0200 @@ -29,8 +29,8 @@ set(PROJECT_HOMEPAGE_URL "https://github.com/babelouest/orcania/") set(PROJECT_BUGREPORT_PATH "https://github.com/babelouest/orcania/issues") set(LIBRARY_VERSION_MAJOR "2") -set(LIBRARY_VERSION_MINOR "2") -set(LIBRARY_VERSION_PATCH "2") +set(LIBRARY_VERSION_MINOR "3") +set(LIBRARY_VERSION_PATCH "0") set(LIBS "-lm") set(PROJECT_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}") @@ -60,7 +60,8 @@ # cmake modules -set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules) +set(O_CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules) +list(APPEND CMAKE_MODULE_PATH "${O_CMAKE_MODULE_PATH}") include(GNUInstallDirs) include(CheckSymbolExists) @@ -207,7 +208,7 @@ pointer_list_test) configure_file( - "${CMAKE_MODULE_PATH}/CTestCustom.cmake.in" + "${O_CMAKE_MODULE_PATH}/CTestCustom.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake" @ONLY) @@ -224,6 +225,18 @@ # install target +if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") + set(PKGCONFIG_TARGET_INCLUDES "${CMAKE_INSTALL_INCLUDEDIR}") +else() + set(PKGCONFIG_TARGET_INCLUDES "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") +endif() + +if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") + set(PKGCONFIG_TARGET_LIBDIR "${CMAKE_INSTALL_LIBDIR}") +else() + set(PKGCONFIG_TARGET_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}") +endif() + option(INSTALL_HEADER "Install the header files" ON) # Install orcania.h or not configure_file(liborcania.pc.in liborcania.pc @ONLY) @@ -253,7 +266,7 @@ if (NOT TARGET uninstall) configure_file( - "${CMAKE_MODULE_PATH}/CMakeUninstall.cmake.in" + "${O_CMAKE_MODULE_PATH}/CMakeUninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) add_custom_target(uninstall diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orcania-2.2.2/include/orcania.h new/orcania-2.3.0/include/orcania.h --- old/orcania-2.2.2/include/orcania.h 2022-03-09 22:23:46.000000000 +0100 +++ new/orcania-2.3.0/include/orcania.h 2022-05-25 16:50:33.000000000 +0200 @@ -38,6 +38,11 @@ #include <stdio.h> #include <stdlib.h> +struct _o_datum { + size_t size; + unsigned char * data; +}; + /** * @defgroup str string functions * These functions are used for string manipulation @@ -522,11 +527,11 @@ /** * o_base64_encode - Base64 encode - * @param src: Data to be encoded - * @param len: Length of the data to be encoded - * @param out: Pointer to output variable - * @param out_len: Pointer to output length variable - * @return : 1 on success, 0 on failure + * @src: Data to be encoded + * @len: Length of the data to be encoded + * @out: Pointer to output variable, you might add up to 2 bytes to out length than expected for safety + * @out_len: Pointer to output length variable + * Returns: 1 on success, 0 on failure * * The nul terminator is not included in out_len. */ @@ -534,11 +539,11 @@ /** * o_base64_decode - Base64 decode - * @param src: Data to be decoded - * @param len: Length of the data to be decoded - * @param out: Pointer to output variable - * @param out_len: Pointer to output length variable - * @return : 1 on success, 0 on failure + * @src: Data to be decoded + * @len: Length of the data to be decoded + * @out: Pointer to output variable, you might add up to 2 bytes to out length than expected for safety + * @out_len: Pointer to output length variable + * Returns: 1 on success, 0 on failure * * The nul terminator is not included in out_len. */ @@ -546,11 +551,11 @@ /** * o_base64url_encode - Base64url encode (url format) - * @param src: Data to be encoded - * @param len: Length of the data to be encoded - * @param out: Pointer to output variable - * @param out_len: Pointer to output length variable - * @return : 1 on success, 0 on failure + * @src: Data to be encoded + * @len: Length of the data to be encoded + * @out: Pointer to output variable, you might add up to 2 bytes to out length than expected for safety + * @out_len: Pointer to output length variable + * Returns: 1 on success, 0 on failure * * The nul terminator is not included in out_len. */ @@ -558,41 +563,113 @@ /** * o_base64url_decode - Base64 decode (url format) + * @src: Data to be decoded + * @len: Length of the data to be decoded + * @out: Pointer to output variable, you might add up to 2 bytes to out length than expected for safety + * @out_len: Pointer to output length variable + * Returns: 1 on success, 0 on failure + * + * The nul terminator is not included in out_len. + */ +int o_base64url_decode(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len); + +/** + * o_base64url_2_base64 - Convert a base64 url format to base64 format - Does not check if src is a valid base64 + * @src: Data to be decoded + * @len: Length of the data to be decoded + * @out: Pointer to output variable + * @out_len: Pointer to output length variable + * Returns: 1 on success, 0 on failure + * + * The nul terminator is not included in out_len. + * out must be at least len+2 + */ +int o_base64url_2_base64(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len); + +/** + * o_base64_2_base64url - Convert a base64 url format to base64 format - Does not check if src is a valid base64url + * @src: Data to be decoded + * @len: Length of the data to be decoded + * @out: Pointer to output variable + * @out_len: Pointer to output length variable + * Returns: 1 on success, 0 on failure + * + * The nul terminator is not included in out_len. + * out must be at least len+2 + */ +int o_base64_2_base64url(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len); + +/** + * o_base64_encode_alloc - Base64 encode - allocate data result in a struct _o_datum * + * @param src: Data to be encoded + * @param len: Length of the data to be encoded + * @param dat: Pointer to a struct _o_datum * to store result + * @return : 1 on success, 0 on failure + * + * dat->data must be o_free'd after use + * The nul terminator is not included in dat->data. + */ +int o_base64_encode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat); + +/** + * o_base64_decode_alloc - Base64 decode - allocate data result in a struct _o_datum * * @param src: Data to be decoded * @param len: Length of the data to be decoded - * @param out: Pointer to output variable - * @param out_len: Pointer to output length variable + * @param dat: Pointer to a struct _o_datum * to store result * @return : 1 on success, 0 on failure * - * The nul terminator is not included in out_len. + * dat->data must be o_free'd after use + * The nul terminator is not included in dat->data. */ -int o_base64url_decode(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len); +int o_base64_decode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat); + +/** + * o_base64url_encode_alloc - Base64url encode (url format) - allocate data result in a struct _o_datum * + * @param src: Data to be encoded + * @param len: Length of the data to be encoded + * @param dat: Pointer to a struct _o_datum * to store result + * @return : 1 on success, 0 on failure + * + * dat->data must be o_free'd after use + * The nul terminator is not included in dat->data. + */ +int o_base64url_encode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat); /** - * o_base64url_2_base64 - Convert a base64 url format to base64 format + * o_base64url_decode_alloc - Base64 decode (url format) - allocate data result in a struct _o_datum * * @param src: Data to be decoded * @param len: Length of the data to be decoded - * @param out: Pointer to output variable - * @param out_len: Pointer to output length variable + * @param dat: Pointer to a struct _o_datum * to store result * @return : 1 on success, 0 on failure * - * The nul terminator is not included in out_len. - * out must be at least len+2 + * dat->data must be o_free'd after use + * The nul terminator is not included in dat->data. */ -int o_base64url_2_base64(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len); +int o_base64url_decode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat); /** - * o_base64url_2_base64 - Convert a base64 format to base64 url format + * o_base64url_2_base64_alloc - Convert a base64 url format to base64 format - allocate data result in a struct _o_datum * * @param src: Data to be decoded * @param len: Length of the data to be decoded - * @param out: Pointer to output variable - * @param out_len: Pointer to output length variable + * @param dat: Pointer to a struct _o_datum * to store result * @return : 1 on success, 0 on failure * - * The nul terminator is not included in out_len. - * out must be at least len+2 + * dat->data must be o_free'd after use + * The nul terminator is not included in dat->data. */ -int o_base64_2_base64url(const unsigned char *src, size_t len, unsigned char * out, size_t * out_len); +int o_base64url_2_base64_alloc(const unsigned char * src, size_t len, struct _o_datum * dat); + +/** + * o_base64_2_base64url_alloc - Convert a base64 format to base64 url format - allocate data result in a struct _o_datum * + * @param src: Data to be decoded + * @param len: Length of the data to be decoded + * @param dat: Pointer to a struct _o_datum * to store result + * @return : 1 on success, 0 on failure + * + * dat->data must be o_free'd after use + * The nul terminator is not included in dat->data. + */ +int o_base64_2_base64url_alloc(const unsigned char * src, size_t len, struct _o_datum * dat); /** * @} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orcania-2.2.2/liborcania.pc.in new/orcania-2.3.0/liborcania.pc.in --- old/orcania-2.2.2/liborcania.pc.in 2022-03-09 22:23:46.000000000 +0100 +++ new/orcania-2.3.0/liborcania.pc.in 2022-05-25 16:50:33.000000000 +0200 @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ -libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ -includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ +libdir=@PKGCONFIG_TARGET_LIBDIR@ +includedir=@PKGCONFIG_TARGET_INCLUDES@ Name: @PROJECT_NAME@ Description: @PROJECT_DESCRIPTION@ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orcania-2.2.2/src/Makefile new/orcania-2.3.0/src/Makefile --- old/orcania-2.2.2/src/Makefile 2022-03-09 22:23:46.000000000 +0100 +++ new/orcania-2.3.0/src/Makefile 2022-05-25 16:50:33.000000000 +0200 @@ -33,8 +33,8 @@ CFLAGS+=-c -fPIC -Wall -Werror -Wextra -I$(ORCANIA_INCLUDE) -D_REENTRANT $(ADDITIONALFLAGS) $(CPPFLAGS) OUTPUT=liborcania.so VERSION_MAJOR=2 -VERSION_MINOR=2 -VERSION_PATCH=2 +VERSION_MINOR=3 +VERSION_PATCH=0 OBJECTS=orcania.o memory.o base64.o LIBSDEP=-lm LIBS=-lc @@ -72,8 +72,8 @@ @cp $(PKGCONFIG_TEMPLATE) $(PKGCONFIG_FILE) @echo Pkgconfig file $(PKGCONFIG_FILE) generated @sed -i -e 's#@CMAKE_INSTALL_PREFIX@#$(DESTDIR)#g' $(PKGCONFIG_FILE) - @sed -i -e 's/@CMAKE_INSTALL_LIBDIR@/lib/g' $(PKGCONFIG_FILE) - @sed -i -e 's/@CMAKE_INSTALL_INCLUDEDIR@/include/g' $(PKGCONFIG_FILE) + @sed -i -e 's#@PKGCONFIG_TARGET_LIBDIR@#$${prefix}/lib#g' $(PKGCONFIG_FILE) + @sed -i -e 's#@PKGCONFIG_TARGET_INCLUDES@#$${prefix}/include#g' $(PKGCONFIG_FILE) @sed -i -e 's/@PROJECT_NAME@/$(PROJECT_NAME)/g' $(PKGCONFIG_FILE) @sed -i -e 's/@PROJECT_DESCRIPTION@/$(PROJECT_DESCRIPTION)/g' $(PKGCONFIG_FILE) @sed -i -e 's|@PROJECT_BUGREPORT_PATH@|$(PROJECT_BUGREPORT_PATH)|g' $(PKGCONFIG_FILE) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orcania-2.2.2/src/base64.c new/orcania-2.3.0/src/base64.c --- old/orcania-2.2.2/src/base64.c 2022-03-09 22:23:46.000000000 +0100 +++ new/orcania-2.3.0/src/base64.c 2022-05-25 16:50:33.000000000 +0200 @@ -38,10 +38,10 @@ *out_len = 0; while (end - in >= 3) { if (pos != NULL) { - *pos++ = table[in[0] >> 2]; - *pos++ = table[((in[0] & 0x03) << 4) | (in[1] >> 4)]; - *pos++ = table[((in[1] & 0x0f) << 2) | (in[2] >> 6)]; - *pos++ = table[in[2] & 0x3f]; + *pos++ = (unsigned char)(table[in[0] >> 2]); + *pos++ = (unsigned char)(table[((in[0] & 0x03) << 4) | (in[1] >> 4)]); + *pos++ = (unsigned char)(table[((in[1] & 0x0f) << 2) | (in[2] >> 6)]); + *pos++ = (unsigned char)(table[in[2] & 0x3f]); } (*out_len) += 4; in += 3; @@ -53,12 +53,12 @@ if (end - in) { if (pos != NULL) { - *pos++ = table[in[0] >> 2]; + *pos++ = (unsigned char)(table[in[0] >> 2]); } (*out_len)++; if (end - in == 1) { if (pos != NULL) { - *pos++ = table[(in[0] & 0x03) << 4]; + *pos++ = (unsigned char)(table[(in[0] & 0x03) << 4]); if (right_pad) { *pos++ = '='; } @@ -70,8 +70,8 @@ } } else { if (pos != NULL) { - *pos++ = table[((in[0] & 0x03) << 4) | (in[1] >> 4)]; - *pos++ = table[(in[1] & 0x0f) << 2]; + *pos++ = (unsigned char)(table[((in[0] & 0x03) << 4) | (in[1] >> 4)]); + *pos++ = (unsigned char)(table[(in[1] & 0x0f) << 2]); } (*out_len) += 2; } @@ -141,9 +141,9 @@ } if (count == 4) { if (pos != NULL) { - *pos++ = (block[0] << 2) | (block[1] >> 4); - *pos++ = (block[1] << 4) | (block[2] >> 2); - *pos++ = (block[2] << 6) | block[3]; + *pos++ = (unsigned char)((block[0] << 2)) | (unsigned char)((block[1] >> 4)); + *pos++ = (unsigned char)((block[1] << 4)) | (unsigned char)((block[2] >> 2)); + *pos++ = (unsigned char)((block[2] << 6)) | (unsigned char)(block[3]); } (*out_len)+=3; count = 0; @@ -175,7 +175,7 @@ * o_base64_encode - Base64 encode * @src: Data to be encoded * @len: Length of the data to be encoded - * @out: Pointer to output variable + * @out: Pointer to output variable, you might add up to 2 bytes to out length than expected for safety * @out_len: Pointer to output length variable * Returns: 1 on success, 0 on failure * @@ -203,7 +203,7 @@ * o_base64url_encode - Base64url encode (url format) * @src: Data to be encoded * @len: Length of the data to be encoded - * @out: Pointer to output variable + * @out: Pointer to output variable, you might add up to 2 bytes to out length than expected for safety * @out_len: Pointer to output length variable * Returns: 1 on success, 0 on failure * @@ -228,7 +228,7 @@ } /** - * o_base64url_2_base64 - Convert a base64 url format to base64 format + * o_base64url_2_base64 - Convert a base64 url format to base64 format - Does not check if src is a valid base64 * @src: Data to be decoded * @len: Length of the data to be decoded * @out: Pointer to output variable @@ -266,7 +266,7 @@ } /** - * o_base64url_2_base64 - Convert a base64 format to base64 url format + * o_base64_2_base64url - Convert a base64 url format to base64 format - Does not check if src is a valid base64url * @src: Data to be decoded * @len: Length of the data to be decoded * @out: Pointer to output variable @@ -298,3 +298,167 @@ return res; } + +/** + * o_base64_encode_alloc - Base64 encode - allocate data result in a struct _o_datum * + * @param src: Data to be encoded + * @param len: Length of the data to be encoded + * @param dat: Pointer to a struct _o_datum * to store result + * @return : 1 on success, 0 on failure + * + * dat->data must be o_free'd after use + * The nul terminator is not included in dat->data. + */ +int o_base64_encode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat) { + int ret = 0; + + if (dat != NULL) { + dat->size = 0; + if ((ret = o_base64_encode(src, len, NULL, &dat->size)) && dat->size) { + if ((dat->data = o_malloc(dat->size+2)) != NULL) { + memset(dat->data, 0, dat->size+2); + ret = o_base64_encode(src, len, dat->data, &dat->size); + } else { + ret = 0; + } + } + } + return ret; +} + +/** + * o_base64_decode_alloc - Base64 decode - allocate data result in a struct _o_datum * + * @param src: Data to be decoded + * @param len: Length of the data to be decoded + * @param dat: Pointer to a struct _o_datum * to store result + * @return : 1 on success, 0 on failure + * + * dat->data must be o_free'd after use + * The nul terminator is not included in dat->data. + */ +int o_base64_decode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat) { + int ret = 0; + + if (dat != NULL) { + dat->size = 0; + if ((ret = o_base64_decode(src, len, NULL, &dat->size)) && dat->size) { + if ((dat->data = o_malloc(dat->size+2)) != NULL) { + memset(dat->data, 0, dat->size+2); + ret = o_base64_decode(src, len, dat->data, &dat->size); + } else { + ret = 0; + } + } + } + return ret; +} + +/** + * o_base64url_encode_alloc - Base64url encode (url format) - allocate data result in a struct _o_datum * + * @param src: Data to be encoded + * @param len: Length of the data to be encoded + * @param dat: Pointer to a struct _o_datum * to store result + * @return : 1 on success, 0 on failure + * + * dat->data must be o_free'd after use + * The nul terminator is not included in dat->data. + */ +int o_base64url_encode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat) { + int ret = 0; + + if (dat != NULL) { + dat->size = 0; + if ((ret = o_base64url_encode(src, len, NULL, &dat->size)) && dat->size) { + if ((dat->data = o_malloc(dat->size+2)) != NULL) { + memset(dat->data, 0, dat->size+2); + ret = o_base64url_encode(src, len, dat->data, &dat->size); + } else { + ret = 0; + } + } + } + return ret; +} + +/** + * o_base64url_decode_alloc - Base64 decode (url format) - allocate data result in a struct _o_datum * + * @param src: Data to be decoded + * @param len: Length of the data to be decoded + * @param dat: Pointer to a struct _o_datum * to store result + * @return : 1 on success, 0 on failure + * + * dat->data must be o_free'd after use + * The nul terminator is not included in dat->data. + */ +int o_base64url_decode_alloc(const unsigned char * src, size_t len, struct _o_datum * dat) { + int ret = 0; + + if (dat != NULL) { + dat->size = 0; + if ((ret = o_base64url_decode(src, len, NULL, &dat->size)) && dat->size) { + if ((dat->data = o_malloc(dat->size+2)) != NULL) { + memset(dat->data, 0, dat->size+2); + ret = o_base64url_decode(src, len, dat->data, &dat->size); + } else { + ret = 0; + } + } + } + return ret; +} + +/** + * o_base64url_2_base64_alloc - Convert a base64 url format to base64 format - allocate data result in a struct _o_datum * + * @param src: Data to be decoded + * @param len: Length of the data to be decoded + * @param dat: Pointer to a struct _o_datum * to store result + * @return : 1 on success, 0 on failure + * + * dat->data must be o_free'd after use + * The nul terminator is not included in dat->data. + */ +int o_base64url_2_base64_alloc(const unsigned char * src, size_t len, struct _o_datum * dat) { + int ret = 0; + unsigned char * out = NULL; + + if (dat != NULL) { + dat->size = 0; + if ((out = o_malloc(len+4)) != NULL) { + if ((ret = o_base64url_2_base64(src, len, out, &dat->size)) && dat->size) { + if ((dat->data = o_malloc(dat->size)) != NULL) { + memcpy(dat->data, out, dat->size); + } + } + } + } + o_free(out); + return ret; +} + +/** + * o_base64_2_base64url_alloc - Convert a base64 format to base64 url format - allocate data result in a struct _o_datum * + * @param src: Data to be decoded + * @param len: Length of the data to be decoded + * @param dat: Pointer to a struct _o_datum * to store result + * @return : 1 on success, 0 on failure + * + * dat->data must be o_free'd after use + * The nul terminator is not included in dat->data. + */ +int o_base64_2_base64url_alloc(const unsigned char * src, size_t len, struct _o_datum * dat) { + int ret = 0; + unsigned char * out = NULL; + + if (dat != NULL) { + dat->size = 0; + if ((out = o_malloc(len)) != NULL) { + if ((ret = o_base64_2_base64url(src, len, out, &dat->size)) && dat->size) { + if ((dat->data = o_malloc(dat->size)) != NULL) { + memcpy(dat->data, out, dat->size); + } + } + } + } + o_free(out); + return ret; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orcania-2.2.2/test/.gitignore new/orcania-2.3.0/test/.gitignore --- old/orcania-2.2.2/test/.gitignore 1970-01-01 01:00:00.000000000 +0100 +++ new/orcania-2.3.0/test/.gitignore 2022-05-25 16:50:33.000000000 +0200 @@ -0,0 +1,5 @@ +valgrind*.txt +str_test +split_test +memory_test +pointer_list_test diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orcania-2.2.2/test/str_test.c new/orcania-2.3.0/test/str_test.c --- old/orcania-2.2.2/test/str_test.c 2022-03-09 22:23:46.000000000 +0100 +++ new/orcania-2.3.0/test/str_test.c 2022-05-25 16:50:33.000000000 +0200 @@ -82,6 +82,52 @@ ck_assert_int_eq(0, memcmp(b64_expected, out, out_len)); } +static void run_test_base64_alloc(const unsigned char * src, size_t src_len, const unsigned char * b64_expected, size_t b64_expected_len, const unsigned char * b64url_expected, size_t b64url_expected_len) { + struct _o_datum dat = {0, NULL}; + + ck_assert_int_eq(o_base64_encode_alloc(src, src_len, &dat), 1); + ck_assert_int_eq(b64_expected_len, dat.size); + ck_assert_str_eq((const char *)dat.data, (const char *)b64_expected); + o_free(dat.data); + dat.data = NULL; + dat.size = 0; + + ck_assert_int_eq(o_base64_decode_alloc(b64_expected, b64_expected_len, &dat), 1); + ck_assert_int_eq(dat.size, src_len); + ck_assert_int_eq(0, memcmp(src, dat.data, dat.size)); + o_free(dat.data); + dat.data = NULL; + dat.size = 0; + + ck_assert_int_eq(o_base64url_encode_alloc(src, src_len, &dat), 1); + ck_assert_int_eq(dat.size, b64url_expected_len); + ck_assert_str_eq((const char *)dat.data, (const char *)b64url_expected); + o_free(dat.data); + dat.data = NULL; + dat.size = 0; + + ck_assert_int_eq(o_base64url_decode_alloc(b64url_expected, b64url_expected_len, &dat), 1); + ck_assert_int_eq(dat.size, src_len); + ck_assert_int_eq(0, memcmp(src, dat.data, dat.size)); + o_free(dat.data); + dat.data = NULL; + dat.size = 0; + + ck_assert_int_eq(o_base64_2_base64url_alloc(b64_expected, b64_expected_len, &dat), 1); + ck_assert_int_eq(dat.size, b64url_expected_len); + ck_assert_int_eq(0, memcmp(b64url_expected, dat.data, dat.size)); + o_free(dat.data); + dat.data = NULL; + dat.size = 0; + + ck_assert_int_eq(o_base64url_2_base64_alloc(b64url_expected, b64url_expected_len, &dat), 1); + ck_assert_int_eq(dat.size, b64_expected_len); + ck_assert_int_eq(0, memcmp(b64_expected, dat.data, dat.size)); + o_free(dat.data); + dat.data = NULL; + dat.size = 0; +} + START_TEST(test_str_replace) { char * str = "abcdeffedcba", * old_1 = "cd", * new_1 = "gh", * old_2 = "f", * target; @@ -538,6 +584,128 @@ } END_TEST +START_TEST(test_base64_alloc) +{ + char * src = "source string", b64_error[] = ";error;"; + struct _o_datum dat = {0, NULL}, dat_dec = {0, NULL}; + ck_assert_int_eq(o_base64_encode_alloc((unsigned char *)src, o_strlen(src), &dat), 1); + ck_assert_int_eq(20, dat.size); + ck_assert_int_eq(0, o_strncmp((const char *)dat.data, "c291cmNlIHN0cmluZw==", dat.size)); + ck_assert_int_eq(o_base64_decode_alloc(dat.data, dat.size, &dat_dec), 1); + ck_assert_int_eq(dat_dec.size, o_strlen(src)); + ck_assert_int_eq(0, o_strncmp((const char *)dat_dec.data, src, dat_dec.size)); + ck_assert_int_eq(o_base64_decode_alloc((unsigned char *)b64_error, o_strlen(b64_error), &dat_dec), 0); + o_free(dat.data); + o_free(dat_dec.data); +} +END_TEST + +START_TEST(test_base64url_alloc) +{ + char * src = "source string", b64_error[] = ";error;"; + struct _o_datum dat = {0, NULL}, dat_dec = {0, NULL}; + ck_assert_int_eq(o_base64url_encode_alloc((unsigned char *)src, o_strlen(src), &dat), 1); + ck_assert_int_eq(18, dat.size); + ck_assert_int_eq(0, o_strncmp((const char *)dat.data, "c291cmNlIHN0cmluZw", dat.size)); + ck_assert_int_eq(o_base64url_decode_alloc(dat.data, dat.size, &dat_dec), 1); + ck_assert_int_eq(dat_dec.size, o_strlen(src)); + ck_assert_int_eq(0, o_strncmp((const char *)dat_dec.data, src, dat_dec.size)); + ck_assert_int_eq(o_base64url_decode_alloc((unsigned char *)b64_error, o_strlen(b64_error), &dat_dec), 0); + o_free(dat.data); + o_free(dat_dec.data); +} +END_TEST + +START_TEST(test_base64_more_test_cases_alloc) +{ + const unsigned char message1[] = "C combines the power and performance of assembly language with the flexibility and ease-of-use of assembly language.", + message2[] = "Bryan is in\nthe kitchen", + message3[] = {0}, + message4[] = {0, 0}, + message5[] = {0, 0, 0}, + message6[] = {0x32, 0x0, 0x0}, + message7[] = "????????? ??????", + message8[] = {0x76, 0x65, 0x72, 0x79, 0x00, 0x20, 0x75, 0x6e, 0x75, 0x73, 0x75, 0x61, 0x6c, 0x9b, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67}, + message9[] = "\377", + message10[] = "\377\377", + message11[] = "\377\377\377", + message12[] = "\xff\xef"; + const unsigned char message1_b64[] = "QyBjb21iaW5lcyB0aGUgcG93ZXIgYW5kIHBlcmZvcm1hbmNlIG9mIGFzc2VtYmx5IGxhbmd1YWdlIHdpdGggdGhlIGZsZXhpYmlsaXR5IGFuZCBlYXNlLW9mLXVzZSBvZiBhc3NlbWJseSBsYW5ndWFnZS4=", + message2_b64[] = "QnJ5YW4gaXMgaW4KdGhlIGtpdGNoZW4=", + message3_b64[] = "AA==", + message4_b64[] = "AAA=", + message5_b64[] = "AAAA", + message6_b64[] = "MgAA", + message7_b64[] = "7JWE7L+g7JWEIO2PrOuLiAA=", + message8_b64[] = "dmVyeQAgdW51c3VhbJsgc3RyaW5n", + message9_b64[] = "/w==", + message10_b64[] = "//8=", + message11_b64[] = "////", + message12_b64[] = "/+8="; + const unsigned char message1_b64url[] = "QyBjb21iaW5lcyB0aGUgcG93ZXIgYW5kIHBlcmZvcm1hbmNlIG9mIGFzc2VtYmx5IGxhbmd1YWdlIHdpdGggdGhlIGZsZXhpYmlsaXR5IGFuZCBlYXNlLW9mLXVzZSBvZiBhc3NlbWJseSBsYW5ndWFnZS4", + message2_b64url[] = "QnJ5YW4gaXMgaW4KdGhlIGtpdGNoZW4", + message3_b64url[] = "AA", + message4_b64url[] = "AAA", + message5_b64url[] = "AAAA", + message6_b64url[] = "MgAA", + message7_b64url[] = "7JWE7L-g7JWEIO2PrOuLiAA", + message8_b64url[] = "dmVyeQAgdW51c3VhbJsgc3RyaW5n", + message9_b64url[] = "_w", + message10_b64url[] = "__8", + message11_b64url[] = "____", + message12_b64url[] = "_-8"; + + run_test_base64_alloc(message1, o_strlen((const char *)message1), message1_b64, o_strlen((const char *)message1_b64), message1_b64url, o_strlen((const char *)message1_b64url)); + run_test_base64_alloc(message2, o_strlen((const char *)message2), message2_b64, o_strlen((const char *)message2_b64), message2_b64url, o_strlen((const char *)message2_b64url)); + run_test_base64_alloc(message3, sizeof(message3), message3_b64, o_strlen((const char *)message3_b64), message3_b64url, o_strlen((const char *)message3_b64url)); + run_test_base64_alloc(message4, sizeof(message4), message4_b64, o_strlen((const char *)message4_b64), message4_b64url, o_strlen((const char *)message4_b64url)); + run_test_base64_alloc(message5, sizeof(message5), message5_b64, o_strlen((const char *)message5_b64), message5_b64url, o_strlen((const char *)message5_b64url)); + run_test_base64_alloc(message6, sizeof(message6), message6_b64, o_strlen((const char *)message6_b64), message6_b64url, o_strlen((const char *)message6_b64url)); + run_test_base64_alloc(message7, sizeof(message7), message7_b64, o_strlen((const char *)message7_b64), message7_b64url, o_strlen((const char *)message7_b64url)); + run_test_base64_alloc(message8, sizeof(message8), message8_b64, o_strlen((const char *)message8_b64), message8_b64url, o_strlen((const char *)message8_b64url)); + run_test_base64_alloc(message9, o_strlen((const char *)message9), message9_b64, o_strlen((const char *)message9_b64), message9_b64url, o_strlen((const char *)message9_b64url)); + run_test_base64_alloc(message10, o_strlen((const char *)message10), message10_b64, o_strlen((const char *)message10_b64), message10_b64url, o_strlen((const char *)message10_b64url)); + run_test_base64_alloc(message11, o_strlen((const char *)message11), message11_b64, o_strlen((const char *)message11_b64), message11_b64url, o_strlen((const char *)message11_b64url)); + run_test_base64_alloc(message12, o_strlen((const char *)message12), message12_b64, o_strlen((const char *)message12_b64), message12_b64url, o_strlen((const char *)message12_b64url)); +} +END_TEST + +START_TEST(test_base64url_2_base64_alloc) +{ + unsigned char src[10] = {0x6f, 0x5b, 0x70, 0x29, 0x27, 0x2d, 0x3d, 0x40, 0x7e, 0x0}; + struct _o_datum dat = {0, NULL}, dat_url = {0, NULL}, dat_conv = {0, NULL}; + ck_assert_int_eq(o_base64_encode_alloc(src, 10, &dat), 1); + ck_assert_int_gt(dat.size, 0); + ck_assert_int_eq(o_base64url_encode_alloc(src, 10, &dat_url), 1); + ck_assert_int_gt(dat_url.size, 0); + ck_assert_int_ne(0, memcmp((const char *)dat.data, (const char *)dat_url.data, dat.size)); + ck_assert_int_eq(o_base64url_2_base64_alloc(dat_url.data, dat_url.size, &dat_conv), 1); + ck_assert_int_eq(dat.size, dat_conv.size); + ck_assert_int_eq(0, memcmp(dat_conv.data, dat.data, dat_conv.size)); + o_free(dat.data); + o_free(dat_url.data); + o_free(dat_conv.data); +} +END_TEST + +START_TEST(test_base64_2_base64url_alloc) +{ + unsigned char src[10] = {0x6f, 0x5b, 0x70, 0x29, 0x27, 0x2d, 0x3d, 0x40, 0x7e, 0x0}; + struct _o_datum dat = {0, NULL}, dat_url = {0, NULL}, dat_conv = {0, NULL}; + ck_assert_int_eq(o_base64_encode_alloc(src, 10, &dat), 1); + ck_assert_int_gt(dat.size, 0); + ck_assert_int_eq(o_base64url_encode_alloc(src, 10, &dat_url), 1); + ck_assert_int_gt(dat_url.size, 0); + ck_assert_int_ne(0, memcmp((const char *)dat.data, (const char *)dat_url.data, dat.size)); + ck_assert_int_eq(o_base64_2_base64url_alloc(dat.data, dat.size, &dat_conv), 1); + ck_assert_int_eq(dat_url.size, dat_conv.size); + ck_assert_int_eq(0, memcmp(dat_conv.data, dat_url.data, dat_conv.size)); + o_free(dat.data); + o_free(dat_url.data); + o_free(dat_conv.data); +} +END_TEST + START_TEST(test_str_null_or_empty) { char a[1] = {0}, * b = NULL, c[] = "test"; @@ -585,6 +753,11 @@ tcase_add_test(tc_core, test_base64url_2_base64); tcase_add_test(tc_core, test_base64_2_base64url); tcase_add_test(tc_core, test_base64_len); + tcase_add_test(tc_core, test_base64_alloc); + tcase_add_test(tc_core, test_base64url_alloc); + tcase_add_test(tc_core, test_base64_more_test_cases_alloc); + tcase_add_test(tc_core, test_base64url_2_base64_alloc); + tcase_add_test(tc_core, test_base64_2_base64url_alloc); tcase_add_test(tc_core, test_string_array); tcase_add_test(tc_core, test_string_array_has_trimmed_value); tcase_add_test(tc_core, test_str_null_or_empty); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/orcania-2.2.2/tools/base64url/.gitignore new/orcania-2.3.0/tools/base64url/.gitignore --- old/orcania-2.2.2/tools/base64url/.gitignore 1970-01-01 01:00:00.000000000 +0100 +++ new/orcania-2.3.0/tools/base64url/.gitignore 2022-05-25 16:50:33.000000000 +0200 @@ -0,0 +1,2 @@ +base64url +valgrind*.txt