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-03-14 19:35:44
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/orcania (Old)
 and      /work/SRC/openSUSE:Factory/.orcania.new.25692 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "orcania"

Mon Mar 14 19:35:44 2022 rev:10 rq:961650 version:2.2.2

Changes:
--------
--- /work/SRC/openSUSE:Factory/orcania/orcania.changes  2021-06-09 
21:52:16.182471278 +0200
+++ /work/SRC/openSUSE:Factory/.orcania.new.25692/orcania.changes       
2022-03-14 19:37:48.782180097 +0100
@@ -1,0 +2,9 @@
+Sun Mar 13 16:41:55 UTC 2022 - Martin Hauke <[email protected]>
+
+- Update to version 2.2.2
+  * Add `o_strnullempty`
+  * Breaking: `trimwhitespace` now returns `const char *` instead
+    of `char *`, might give compiler warning
+  * Refactor `o_base64*` functions
+
+-------------------------------------------------------------------

Old:
----
  orcania-2.2.1.tar.gz

New:
----
  orcania-2.2.2.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ orcania.spec ++++++
--- /var/tmp/diff_new_pack.bV6bBT/_old  2022-03-14 19:37:49.206180605 +0100
+++ /var/tmp/diff_new_pack.bV6bBT/_new  2022-03-14 19:37:49.210180610 +0100
@@ -1,7 +1,7 @@
 #
 # spec file for package orcania
 #
-# Copyright (c) 2021 SUSE LLC
+# Copyright (c) 2022 SUSE LLC
 # Copyright (c) 2018-2021, Martin Hauke <[email protected]>
 #
 # All modifications and additions to the file contributed by third parties
@@ -19,7 +19,7 @@
 
 %define sover 2_2
 Name:           orcania
-Version:        2.2.1
+Version:        2.2.2
 Release:        0
 Summary:        MISC function Library
 License:        LGPL-2.1-or-later

++++++ orcania-2.2.1.tar.gz -> orcania-2.2.2.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/orcania-2.2.1/CHANGELOG.md 
new/orcania-2.2.2/CHANGELOG.md
--- old/orcania-2.2.1/CHANGELOG.md      2021-06-02 13:42:40.000000000 +0200
+++ new/orcania-2.2.2/CHANGELOG.md      2022-03-09 22:23:46.000000000 +0100
@@ -1,5 +1,11 @@
 # Orcania Changelog
 
+## 2.2.2
+
+- Add `o_strnullempty`
+- Breaking: `trimwhitespace` now returns `const char *` instead of `char *`, 
might give compiler warning
+- Refactor `o_base64*` functions
+
 ## 2.2.1
 
 - Add ld flags in liborcania.pc on static build
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/orcania-2.2.1/CMakeLists.txt 
new/orcania-2.2.2/CMakeLists.txt
--- old/orcania-2.2.1/CMakeLists.txt    2021-06-02 13:42:40.000000000 +0200
+++ new/orcania-2.2.2/CMakeLists.txt    2022-03-09 22:23:46.000000000 +0100
@@ -4,7 +4,7 @@
 # CMake file used to build all programs
 #
 # Copyright 2018 Silvio Clecio <[email protected]>
-# Copyright 2018-2020 Nicolas Mora <[email protected]>
+# Copyright 2018-2022 Nicolas Mora <[email protected]>
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the MIT License
@@ -30,7 +30,7 @@
 set(PROJECT_BUGREPORT_PATH "https://github.com/babelouest/orcania/issues";)
 set(LIBRARY_VERSION_MAJOR "2")
 set(LIBRARY_VERSION_MINOR "2")
-set(LIBRARY_VERSION_PATCH "1")
+set(LIBRARY_VERSION_PATCH "2")
 set(LIBS "-lm")
 
 set(PROJECT_VERSION 
"${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}")
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/orcania-2.2.1/Makefile new/orcania-2.2.2/Makefile
--- old/orcania-2.2.1/Makefile  2021-06-02 13:42:40.000000000 +0200
+++ new/orcania-2.2.2/Makefile  2022-03-09 22:23:46.000000000 +0100
@@ -3,7 +3,7 @@
 #
 # Makefile used to build all programs
 #
-# Copyright 2017-2020 Nicolas Mora <[email protected]>
+# Copyright 2017-2022 Nicolas Mora <[email protected]>
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public License
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/orcania-2.2.1/include/orcania-cfg.h.in 
new/orcania-2.2.2/include/orcania-cfg.h.in
--- old/orcania-2.2.1/include/orcania-cfg.h.in  2021-06-02 13:42:40.000000000 
+0200
+++ new/orcania-2.2.2/include/orcania-cfg.h.in  2022-03-09 22:23:46.000000000 
+0100
@@ -7,7 +7,7 @@
  * 
  * orcania-cfg.h.in: configuration file
  * 
- * Copyright 2018-2020 Nicolas Mora <[email protected]>
+ * Copyright 2018-2022 Nicolas Mora <[email protected]>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/orcania-2.2.1/include/orcania.h 
new/orcania-2.2.2/include/orcania.h
--- old/orcania-2.2.1/include/orcania.h 2021-06-02 13:42:40.000000000 +0200
+++ new/orcania-2.2.2/include/orcania.h 2022-03-09 22:23:46.000000000 +0100
@@ -8,7 +8,7 @@
  * 
  * orcania.h: public header file
  * 
- * Copyright 2015-2020 Nicolas Mora <[email protected]>
+ * Copyright 2015-2022 Nicolas Mora <[email protected]>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -203,6 +203,12 @@
 const char * o_strrnchr(const char * haystack, size_t len, char c);
 
 /**
+ * o_strnullempty
+ * return true if s is NULL or empty string, false otherwise
+ */
+int o_strnullempty(const char * s);
+
+/**
  * o_strlen
  * a modified version of strlen that don't crash when s is NULL
  * @param s the string to calculate length
@@ -216,7 +222,7 @@
  * @param str the string to trim
  * @return the trimmed str
  */
-char * trimwhitespace(char * str);
+const char * trimwhitespace(char * str);
 
 /**
  * Remove string of beginning and ending given character
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/orcania-2.2.1/src/Makefile 
new/orcania-2.2.2/src/Makefile
--- old/orcania-2.2.1/src/Makefile      2021-06-02 13:42:40.000000000 +0200
+++ new/orcania-2.2.2/src/Makefile      2022-03-09 22:23:46.000000000 +0100
@@ -3,7 +3,7 @@
 #
 # Makefile used to build the software
 #
-# Copyright 2014-2020 Nicolas Mora <[email protected]>
+# Copyright 2014-2022 Nicolas Mora <[email protected]>
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public License
@@ -34,7 +34,7 @@
 OUTPUT=liborcania.so
 VERSION_MAJOR=2
 VERSION_MINOR=2
-VERSION_PATCH=1
+VERSION_PATCH=2
 OBJECTS=orcania.o memory.o base64.o
 LIBSDEP=-lm
 LIBS=-lc
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/orcania-2.2.1/src/base64.c 
new/orcania-2.2.2/src/base64.c
--- old/orcania-2.2.1/src/base64.c      2021-06-02 13:42:40.000000000 +0200
+++ new/orcania-2.2.2/src/base64.c      2022-03-09 22:23:46.000000000 +0100
@@ -1,7 +1,7 @@
 /*
  * Base64 encoding/decoding (RFC1341)
  * Copyright (c) 2005-2011, Jouni Malinen <[email protected]>
- * Copyright (c) 2017-2020, Nicolas Mora <[email protected]>
+ * Copyright (c) 2017-2022, Nicolas Mora <[email protected]>
  *
  * This software may be distributed under the terms of the BSD license.
  */
@@ -13,17 +13,12 @@
 static const unsigned char base64_table[65] =
   "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
-/**
- * o_base64_encode - Base64 encode
- * @src: Data to be encoded
- * @len: Length of the data to be encoded
- * @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.
- */
-int o_base64_encode(const unsigned char * src, size_t len, unsigned char * 
out, size_t * out_len) {
+static const unsigned char base64_url_table[65] =
+  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
+
+static size_t table_size = 65;
+
+static int _o_base64_encode_agnostic(const unsigned char * src, size_t len, 
unsigned char * out, size_t * out_len, const unsigned char * table, int 
right_pad) {
   unsigned char * pos;
   const unsigned char * end, * in;
   size_t olen;
@@ -43,10 +38,10 @@
   *out_len = 0;
   while (end - in >= 3) {
     if (pos != NULL) {
-      *pos++ = base64_table[in[0] >> 2];
-      *pos++ = base64_table[((in[0] & 0x03) << 4) | (in[1] >> 4)];
-      *pos++ = base64_table[((in[1] & 0x0f) << 2) | (in[2] >> 6)];
-      *pos++ = base64_table[in[2] & 0x3f];
+      *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];
     }
     (*out_len) += 4;
     in += 3;
@@ -58,56 +53,57 @@
 
   if (end - in) {
     if (pos != NULL) {
-      *pos++ = base64_table[in[0] >> 2];
+      *pos++ = table[in[0] >> 2];
     }
     (*out_len)++;
     if (end - in == 1) {
       if (pos != NULL) {
-        *pos++ = base64_table[(in[0] & 0x03) << 4];
-        *pos++ = '=';
+        *pos++ = table[(in[0] & 0x03) << 4];
+        if (right_pad) {
+          *pos++ = '=';
+        }
+      }
+      if (right_pad) {
+        (*out_len) += 2;
+      } else {
+        (*out_len)++;
       }
-      (*out_len) += 2;
     } else {
       if (pos != NULL) {
-        *pos++ = base64_table[((in[0] & 0x03) << 4) | (in[1] >> 4)];
-        *pos++ = base64_table[(in[1] & 0x0f) << 2];
+        *pos++ = table[((in[0] & 0x03) << 4) | (in[1] >> 4)];
+        *pos++ = table[(in[1] & 0x0f) << 2];
       }
       (*out_len) += 2;
     }
-    if (pos != NULL) {
+    if (pos != NULL && right_pad) {
       *pos++ = '=';
     }
-    (*out_len)++;
+    if (right_pad) {
+      (*out_len)++;
+    }
   }
 
-  if (pos != NULL) {
-    *pos = '\0';
-  }
   return 1;
 }
 
-/**
- * o_base64_decode - Base64 decode
- * @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.
- */
-int o_base64_decode(const unsigned char *src, size_t len, unsigned char * out, 
size_t * out_len) {
-  unsigned char dtable[256], *pos = out, block[4], tmp;
-  size_t i, count;
+static int o_base64_decode_agnostic(const unsigned char *src, size_t len, 
unsigned char * out, size_t * out_len, const unsigned char * table, int 
right_pad) {
+  unsigned char dtable[256], *pos = out, block[4] = {0}, tmp;
+  size_t i, count, unpad = 0;
   int pad = 0;
   
   if (src == NULL || !len || out_len == NULL) {
     return 0;
   }
 
+  if (len % 4 == 2) {
+    unpad = 2;
+  } else if (len % 4 == 3) {
+    unpad = 1;
+  }
+
   memset(dtable, 0x80, 256);
-  for (i = 0; i < sizeof(base64_table) - 1; i++) {
-    dtable[base64_table[i]] = (unsigned char) i;
+  for (i = 0; i < table_size - 1; i++) {
+    dtable[table[i]] = (unsigned char) i;
   }
   dtable['='] = 0;
 
@@ -118,14 +114,14 @@
     }
   }
 
-  if (count == 0 || count % 4) {
+  if (right_pad && (count == 0 || count % 4)) {
     return 0;
   }
 
   count = 0;
   *out_len = 0;
   for (i = 0; i < len; i++) {
-    if (!o_strchr((const char *)base64_table, src[i]) && src[i] != '=' && 
src[i] != '\n' && src[i] != '\t' && src[i] != ' ') {
+    if (!o_strchr((const char *)table, src[i]) && src[i] != '=' && src[i] != 
'\n' && src[i] != '\t' && src[i] != ' ') {
       // character invalid
       return 0;
     }
@@ -139,6 +135,10 @@
     }
     block[count] = tmp;
     count++;
+    if (i == len-1) {
+      count = 4;
+      (*out_len) -= unpad;
+    }
     if (count == 4) {
       if (pos != NULL) {
         *pos++ = (block[0] << 2) | (block[1] >> 4);
@@ -164,6 +164,7 @@
         }
         break;
       }
+      memset(block, 0, 4);
     }
   }
 
@@ -171,6 +172,34 @@
 }
 
 /**
+ * o_base64_encode - Base64 encode
+ * @src: Data to be encoded
+ * @len: Length of the data to be encoded
+ * @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.
+ */
+int o_base64_encode(const unsigned char * src, size_t len, unsigned char * 
out, size_t * out_len) {
+  return _o_base64_encode_agnostic(src, len, out, out_len, base64_table, 1);
+}
+
+/**
+ * o_base64_decode - Base64 decode
+ * @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_base64_decode(const unsigned char *src, size_t len, unsigned char * out, 
size_t * out_len) {
+  return o_base64_decode_agnostic(src, len, out, out_len, base64_table, 1);
+}
+
+/**
  * o_base64url_encode - Base64url encode (url format)
  * @src: Data to be encoded
  * @len: Length of the data to be encoded
@@ -181,68 +210,21 @@
  * The nul terminator is not included in out_len.
  */
 int o_base64url_encode(const unsigned char * src, size_t len, unsigned char * 
out, size_t * out_len) {
-  int res = 0;
-  size_t index;
-  double calc;
-  
-  if (out != NULL) {
-    res = o_base64_encode(src, len, out, out_len);
-    if (res) {
-      if (*out_len >= 2 && out[*out_len - 2] == '=') {
-        out[*out_len - 2] = '\0';
-        (*out_len) -= 2;
-      } else if (*out_len && out[*out_len - 1] == '=') {
-        out[*out_len - 1] = '\0';
-        (*out_len)--;
-      }
-      for (index = 0; index < *out_len; index++) {
-        if (out[index] == '+') {
-          out[index] = '-';
-        } else if (out[index] == '/') {
-          out[index] = '_';
-        }
-      }
-    }
-  } else if (len && out_len != NULL) {
-    calc = (4 * (double)len) / 3;
-    if (calc != floor(calc)) {
-      calc = floor(calc)+1;
-    }
-    *out_len = calc;
-    res = 1;
-  }
-  return res;
+  return _o_base64_encode_agnostic(src, len, out, out_len, base64_url_table, 
0);
 }
 
 /**
  * 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
+ * @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) {
-  int res = 0;
-  size_t src_cpy_len;
-  unsigned char * src_cpy;
-  
-  if (src) {
-    src_cpy = o_malloc(len+3);
-    if (src_cpy != NULL) {
-      if (o_base64url_2_base64(src, len, src_cpy, &src_cpy_len)) {
-        res = o_base64_decode(src_cpy, src_cpy_len, out, out_len);
-      } else {
-        res = 1;
-      }
-      o_free(src_cpy);
-    } else {
-      res = 0;
-    }
-  }
-  return res;
+  return o_base64_decode_agnostic(src, len, out, out_len, base64_url_table, 0);
 }
 
 /**
@@ -260,7 +242,7 @@
   int res = 0;
   size_t index;
   
-  if (src) {
+  if (src != NULL && len && out != NULL && out_len != NULL) {
     memcpy(out, src, len);
     *out_len = len;
     for (index = 0; index < len; index++) {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/orcania-2.2.1/src/memory.c 
new/orcania-2.2.2/src/memory.c
--- old/orcania-2.2.1/src/memory.c      2021-06-02 13:42:40.000000000 +0200
+++ new/orcania-2.2.2/src/memory.c      2022-03-09 22:23:46.000000000 +0100
@@ -1,5 +1,5 @@
-/*
- * Copyright (c) 2017-2020 Nicolas Mora <[email protected]>
+/**
+ * Copyright (c) 2017-2022 Nicolas Mora <[email protected]>
  * Copyright (c) 2009-2014 Petri Lehtinen <[email protected]>
  * Copyright (c) 2011-2012 Basile Starynkevitch <[email protected]>
  *
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/orcania-2.2.1/src/orcania.c 
new/orcania-2.2.2/src/orcania.c
--- old/orcania-2.2.1/src/orcania.c     2021-06-02 13:42:40.000000000 +0200
+++ new/orcania-2.2.2/src/orcania.c     2022-03-09 22:23:46.000000000 +0100
@@ -7,7 +7,7 @@
  * 
  * orcania.c: main functions definitions
  * 
- * Copyright 2015-2020 Nicolas Mora <[email protected]>
+ * Copyright 2015-2022 Nicolas Mora <[email protected]>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -74,12 +74,12 @@
     memcpy(pre, source, pre_len);
     pre[pre_len] = '\0';
     
-    next = str_replace(source+strlen(pre)+strlen(str_old), str_old, str_new);
+    next = str_replace(source+o_strlen(pre)+o_strlen(str_old), str_old, 
str_new);
     if (next == NULL) {
       o_free(pre);
       return NULL;
     }
-    len = ((ptr-source)+strlen(str_new)+strlen(next));
+    len = ((ptr-source)+o_strlen(str_new)+o_strlen(next));
     to_return = o_malloc((len+1)*sizeof(char));
     if (to_return == NULL) {
       o_free(pre);
@@ -361,7 +361,7 @@
   size_t needle_len;
 
   /* segfault here if needle is not NULL terminated */
-  if (0 == (needle_len = strlen(needle)))
+  if (0 == (needle_len = o_strlen(needle)))
     return (char *)haystack;
 
   for (i=0; i<=(int)(len - needle_len); i++) {
@@ -427,6 +427,14 @@
 }
 
 /**
+ * o_strnullempty
+ * return true if s is NULL or empty string, false otherwise
+ */
+int o_strnullempty(const char * s) {
+  return (s == NULL || s[0] == '\0');
+}
+
+/**
  * Split a string into an array of strings using separator string
  * return the number of elements to be returned, 0 on error
  * if return_array is not NULL, set the returned array in it
@@ -454,7 +462,7 @@
         }
       }
       result++;
-      begin = token+strlen(separator);
+      begin = token+o_strlen(separator);
       token = strstr(begin, separator);
     }
     if (return_array != NULL) {
@@ -517,7 +525,7 @@
 /**
  * Remove string of beginning and ending whitespaces
  */
-char * trimwhitespace(char * str) {
+const char * trimwhitespace(char * str) {
   char * end;
 
   if (str == NULL) {
@@ -635,7 +643,8 @@
  */
 int string_array_has_trimmed_value(const char ** array, const char * needle) {
   int i, to_return = 0;
-  char * duplicate_needle, * trimmed_needle, * duplicate_value, * 
trimmed_value;
+  char * duplicate_needle, * duplicate_value;
+  const char * trimmed_needle, * trimmed_value;
   if (array != NULL && needle != NULL) {
     duplicate_needle = o_strdup(needle);
     if (duplicate_needle != NULL) {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/orcania-2.2.1/test/str_test.c 
new/orcania-2.2.2/test/str_test.c
--- old/orcania-2.2.1/test/str_test.c   2021-06-02 13:42:40.000000000 +0200
+++ new/orcania-2.2.2/test/str_test.c   2022-03-09 22:23:46.000000000 +0100
@@ -9,6 +9,79 @@
 #include <check.h>
 #include "orcania.h"
 
+static void run_test_base64(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) {
+  unsigned char out[256] = {0}, * out_m;
+  size_t out_len = 0;
+
+  memset(out, 0, 256);
+  out_len = 0;
+  ck_assert_int_eq(o_base64_encode(src, src_len, out, &out_len), 1);
+  ck_assert_int_eq(out_len, b64_expected_len);
+  ck_assert_str_eq((const char *)out, (const char *)b64_expected);
+
+  out_len = 0;
+  ck_assert_int_eq(o_base64_encode(src, src_len, NULL, &out_len), 1);
+  ck_assert_int_eq(out_len, b64_expected_len);
+  out_m = o_malloc(out_len);
+  out_len = 0;
+  ck_assert_int_eq(o_base64_encode(src, src_len, out_m, &out_len), 1);
+  o_free(out_m);
+
+  memset(out, 0, 256);
+  out_len = 0;
+  ck_assert_int_eq(o_base64_decode(b64_expected, b64_expected_len, out, 
&out_len), 1);
+  ck_assert_int_eq(out_len, src_len);
+  ck_assert_int_eq(0, memcmp(src, out, out_len));
+
+  out_len = 0;
+  ck_assert_int_eq(o_base64_decode(b64_expected, b64_expected_len, NULL, 
&out_len), 1);
+  ck_assert_int_eq(out_len, src_len);
+  out_m = o_malloc(out_len+2);
+  out_len = 0;
+  ck_assert_int_eq(o_base64_decode(b64_expected, b64_expected_len, out_m, 
&out_len), 1);
+  o_free(out_m);
+
+  memset(out, 0, 256);
+  out_len = 0;
+  ck_assert_int_eq(o_base64url_encode(src, src_len, out, &out_len), 1);
+  ck_assert_int_eq(out_len, b64url_expected_len);
+  ck_assert_str_eq((const char *)out, (const char *)b64url_expected);
+
+  out_len = 0;
+  ck_assert_int_eq(o_base64url_encode(src, src_len, NULL, &out_len), 1);
+  ck_assert_int_eq(out_len, b64url_expected_len);
+  out_m = o_malloc(out_len);
+  out_len = 0;
+  ck_assert_int_eq(o_base64url_encode(src, src_len, out_m, &out_len), 1);
+  o_free(out_m);
+
+  memset(out, 0, 256);
+  out_len = 0;
+  ck_assert_int_eq(o_base64url_decode(b64url_expected, b64url_expected_len, 
out, &out_len), 1);
+  ck_assert_int_eq(out_len, src_len);
+  ck_assert_int_eq(0, memcmp(src, out, out_len));
+
+  out_len = 0;
+  ck_assert_int_eq(o_base64url_decode(b64url_expected, b64url_expected_len, 
NULL, &out_len), 1);
+  ck_assert_int_eq(out_len, src_len);
+  out_m = o_malloc(out_len+2);
+  out_len = 0;
+  ck_assert_int_eq(o_base64url_decode(b64url_expected, b64url_expected_len, 
out_m, &out_len), 1);
+  o_free(out_m);
+
+  memset(out, 0, 256);
+  out_len = 0;
+  ck_assert_int_eq(o_base64_2_base64url(b64_expected, b64_expected_len, out, 
&out_len), 1);
+  ck_assert_int_eq(out_len, b64url_expected_len);
+  ck_assert_int_eq(0, memcmp(b64url_expected, out, out_len));
+  
+  memset(out, 0, 256);
+  out_len = 0;
+  ck_assert_int_eq(o_base64url_2_base64(b64url_expected, b64url_expected_len, 
out, &out_len), 1);
+  ck_assert_int_eq(out_len, b64_expected_len);
+  ck_assert_int_eq(0, memcmp(b64_expected, out, out_len));
+}
+
 START_TEST(test_str_replace)
 {
   char * str = "abcdeffedcba", * old_1 = "cd", * new_1 = "gh", * old_2 = "f", 
* target;
@@ -40,10 +113,10 @@
 START_TEST(test_o_strndup)
 {
   char * str = "abcdeffedcba", * target;
-  target = o_strndup(str, strlen(str));
+  target = o_strndup(str, o_strlen(str));
   ck_assert_str_eq(target, str);
   o_free(target);
-  target = o_strndup(str, strlen(str)-2);
+  target = o_strndup(str, o_strlen(str)-2);
   ck_assert_str_eq(target, "abcdeffedc");
   o_free(target);
   ck_assert_ptr_eq(o_strndup(NULL, 12), NULL);
@@ -67,11 +140,11 @@
 START_TEST(test_o_strncmp)
 {
   char * str_1 = "abcdeffedcba", * str_2 = "abc", * str_3 = "abcdeffedcba";
-  ck_assert_int_eq(o_strncmp(str_1, str_3, strlen(str_3)), 0);
-  ck_assert_int_eq(o_strncmp(str_1, str_2, strlen(str_2)), 0);
-  ck_assert_int_ne(o_strncmp(str_1, str_2, strlen(str_1)), 0);
-  ck_assert_int_ne(o_strncmp(str_1, NULL, strlen(str_1)), 0);
-  ck_assert_int_ne(o_strncmp(NULL, str_1, strlen(str_1)), 0);
+  ck_assert_int_eq(o_strncmp(str_1, str_3, o_strlen(str_3)), 0);
+  ck_assert_int_eq(o_strncmp(str_1, str_2, o_strlen(str_2)), 0);
+  ck_assert_int_ne(o_strncmp(str_1, str_2, o_strlen(str_1)), 0);
+  ck_assert_int_ne(o_strncmp(str_1, NULL, o_strlen(str_1)), 0);
+  ck_assert_int_ne(o_strncmp(NULL, str_1, o_strlen(str_1)), 0);
   ck_assert_int_eq(o_strncmp(NULL, NULL, 0), 0);
   ck_assert_int_eq(o_strncmp(NULL, NULL, 1), 0);
 }
@@ -91,11 +164,11 @@
 START_TEST(test_o_strncasecmp)
 {
   char * str_1 = "abcdeFfedcba", * str_2 = "abC", * str_3 = "abCdeffedCba";
-  ck_assert_int_eq(o_strncasecmp(str_1, str_3, strlen(str_3)), 0);
-  ck_assert_int_eq(o_strncasecmp(str_1, str_2, strlen(str_2)), 0);
-  ck_assert_int_ne(o_strncasecmp(str_1, str_2, strlen(str_1)), 0);
-  ck_assert_int_ne(o_strncasecmp(str_1, NULL, strlen(str_1)), 0);
-  ck_assert_int_ne(o_strncasecmp(NULL, str_1, strlen(str_1)), 0);
+  ck_assert_int_eq(o_strncasecmp(str_1, str_3, o_strlen(str_3)), 0);
+  ck_assert_int_eq(o_strncasecmp(str_1, str_2, o_strlen(str_2)), 0);
+  ck_assert_int_ne(o_strncasecmp(str_1, str_2, o_strlen(str_1)), 0);
+  ck_assert_int_ne(o_strncasecmp(str_1, NULL, o_strlen(str_1)), 0);
+  ck_assert_int_ne(o_strncasecmp(NULL, str_1, o_strlen(str_1)), 0);
   ck_assert_int_eq(o_strncasecmp(NULL, NULL, 0), 0);
   ck_assert_int_eq(o_strncasecmp(NULL, NULL, 1), 0);
 }
@@ -137,12 +210,12 @@
 START_TEST(test_o_strnstr)
 {
   char * str_1 = "abcdeffedcba", * str_2 = "def", * str_3 = "bob";
-  ck_assert_ptr_ne(o_strnstr(str_1, str_2, strlen(str_1)), NULL);
-  ck_assert_ptr_eq(o_strnstr(str_1, str_3, strlen(str_1)), NULL);
+  ck_assert_ptr_ne(o_strnstr(str_1, str_2, o_strlen(str_1)), NULL);
+  ck_assert_ptr_eq(o_strnstr(str_1, str_3, o_strlen(str_1)), NULL);
   ck_assert_ptr_eq(o_strnstr(str_1, str_3, 0), NULL);
-  ck_assert_ptr_eq(o_strnstr(NULL, str_3, strlen(str_3)), NULL);
-  ck_assert_ptr_eq(o_strnstr(str_1, NULL, strlen(str_1)), NULL);
-  ck_assert_ptr_eq(o_strnstr(NULL, NULL, strlen(str_3)), NULL);
+  ck_assert_ptr_eq(o_strnstr(NULL, str_3, o_strlen(str_3)), NULL);
+  ck_assert_ptr_eq(o_strnstr(str_1, NULL, o_strlen(str_1)), NULL);
+  ck_assert_ptr_eq(o_strnstr(NULL, NULL, o_strlen(str_3)), NULL);
 }
 END_TEST
 
@@ -285,10 +358,11 @@
 
 START_TEST(test_base64)
 {
-  char * src = "source string", encoded[128], decoded[128], b64_error[] = 
";error;";
+  char * src = "source string", encoded[128] = {0}, decoded[128] = {0}, 
b64_error[] = ";error;";
   size_t encoded_size, decoded_size;
   ck_assert_int_eq(o_base64_encode((unsigned char *)src, o_strlen(src), 
(unsigned char *)encoded, &encoded_size), 1);
   ck_assert_str_eq(encoded, "c291cmNlIHN0cmluZw==");
+  ck_assert_int_eq(20, encoded_size);
   ck_assert_int_eq(o_base64_decode((unsigned char *)encoded, encoded_size, 
(unsigned char *)decoded, &decoded_size), 1);
   ck_assert_str_eq(decoded, src);
   ck_assert_int_eq(decoded_size, o_strlen(src));
@@ -297,12 +371,67 @@
 }
 END_TEST
 
+START_TEST(test_base64_more_test_cases)
+{
+  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(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(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(message3, sizeof(message3), message3_b64, o_strlen((const 
char *)message3_b64), message3_b64url, o_strlen((const char *)message3_b64url));
+  run_test_base64(message4, sizeof(message4), message4_b64, o_strlen((const 
char *)message4_b64), message4_b64url, o_strlen((const char *)message4_b64url));
+  run_test_base64(message5, sizeof(message5), message5_b64, o_strlen((const 
char *)message5_b64), message5_b64url, o_strlen((const char *)message5_b64url));
+  run_test_base64(message6, sizeof(message6), message6_b64, o_strlen((const 
char *)message6_b64), message6_b64url, o_strlen((const char *)message6_b64url));
+  run_test_base64(message7, sizeof(message7), message7_b64, o_strlen((const 
char *)message7_b64), message7_b64url, o_strlen((const char *)message7_b64url));
+  run_test_base64(message8, sizeof(message8), message8_b64, o_strlen((const 
char *)message8_b64), message8_b64url, o_strlen((const char *)message8_b64url));
+  run_test_base64(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(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(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(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)
 {
-  char * src = "source string", encoded[128], decoded[128], b64_error[] = 
";error;";
+  char * src = "source string", encoded[128] = {0}, decoded[128] = {0}, 
b64_error[] = ";error;";
   size_t encoded_size, decoded_size;
   ck_assert_int_eq(o_base64url_encode((unsigned char *)src, o_strlen(src), 
(unsigned char *)encoded, &encoded_size), 1);
   ck_assert_str_eq(encoded, "c291cmNlIHN0cmluZw");
+  ck_assert_int_eq(18, encoded_size);
   ck_assert_int_eq(o_base64url_decode((unsigned char *)encoded, encoded_size, 
(unsigned char *)decoded, &decoded_size), 1);
   ck_assert_str_eq(decoded, src);
   ck_assert_int_eq(decoded_size, o_strlen(src));
@@ -347,7 +476,7 @@
 
 START_TEST(test_base64_len)
 {
-  char * src1 = "a", * src2 = "aa", * src3 = "aaa", * src4 = "aaaa", * src5 = 
"aaaaa", * src = "source string", encoded[128];
+  char * src1 = "a", * src2 = "aa", * src3 = "aaa", * src4 = "aaaa", * src5 = 
"aaaaa", * src = "source string", encoded[128] = {0};
   char * src1_enc = "YQ==", * src2_enc = "YWE=", * src3_enc = "YWFh", 
*src4_enc = "YWFhYQ==", *src5_enc = "YWFhYWE=";
   size_t encoded_size, decoded_size;
   
@@ -362,7 +491,7 @@
   ck_assert_int_eq(o_base64url_encode((unsigned char *)src, o_strlen(src), 
(unsigned char *)encoded, &encoded_size), 1);
   ck_assert_int_eq(o_base64url_decode((unsigned char *)encoded, encoded_size, 
NULL, &decoded_size), 1);
   ck_assert_int_eq(decoded_size, 13);
-  
+
   ck_assert_int_eq(o_base64_encode((unsigned char *)src1, o_strlen(src1), 
NULL, &encoded_size), 1);
   ck_assert_int_eq(encoded_size, 4);
   ck_assert_int_eq(o_base64_encode((unsigned char *)src2, o_strlen(src2), 
NULL, &encoded_size), 1);
@@ -409,6 +538,20 @@
 }
 END_TEST
 
+START_TEST(test_str_null_or_empty)
+{
+  char a[1] = {0}, * b = NULL, c[] = "test";
+  
+  ck_assert_int_eq(1, o_strnullempty(a));
+  ck_assert_int_eq(1, o_strnullempty(b));
+  ck_assert_int_eq(0, o_strnullempty(c));
+  c[2] = '\0';
+  ck_assert_int_eq(0, o_strnullempty(c));
+  c[0] = '\0';
+  ck_assert_int_eq(1, o_strnullempty(c));
+}
+END_TEST
+
 static Suite *orcania_suite(void)
 {
        Suite *s;
@@ -437,12 +580,14 @@
        tcase_add_test(tc_core, test_trimwhitespace);
        tcase_add_test(tc_core, test_trimcharacter);
        tcase_add_test(tc_core, test_base64);
+       tcase_add_test(tc_core, test_base64_more_test_cases);
        tcase_add_test(tc_core, test_base64url);
        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_string_array);
        tcase_add_test(tc_core, test_string_array_has_trimmed_value);
+       tcase_add_test(tc_core, test_str_null_or_empty);
        tcase_set_timeout(tc_core, 30);
        suite_add_tcase(s, tc_core);
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/orcania-2.2.1/tools/base64url/Makefile 
new/orcania-2.2.2/tools/base64url/Makefile
--- old/orcania-2.2.1/tools/base64url/Makefile  2021-06-02 13:42:40.000000000 
+0200
+++ new/orcania-2.2.2/tools/base64url/Makefile  2022-03-09 22:23:46.000000000 
+0100
@@ -3,7 +3,7 @@
 #
 # Makefile used to build the software
 #
-# Copyright 2021 Nicolas Mora <[email protected]>
+# Copyright 2021-2022 Nicolas Mora <[email protected]>
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU GENERAL PUBLIC LICENSE
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/orcania-2.2.1/tools/base64url/README.md 
new/orcania-2.2.2/tools/base64url/README.md
--- old/orcania-2.2.1/tools/base64url/README.md 2021-06-02 13:42:40.000000000 
+0200
+++ new/orcania-2.2.2/tools/base64url/README.md 2022-03-09 22:23:46.000000000 
+0100
@@ -1,6 +1,6 @@
 # base64url: Base64Url encode or decode FILE, or standard input, to standard 
output.
 
-Copyright 2021 Nicolas Mora <[email protected]>
+Copyright 2021-2022 Nicolas Mora <[email protected]>
 
 This program is free software; you can redistribute it and/or modify it under 
the terms of the GPL3 License.
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/orcania-2.2.1/tools/base64url/base64url.1 
new/orcania-2.2.2/tools/base64url/base64url.1
--- old/orcania-2.2.1/tools/base64url/base64url.1       2021-06-02 
13:42:40.000000000 +0200
+++ new/orcania-2.2.2/tools/base64url/base64url.1       2022-03-09 
22:23:46.000000000 +0100
@@ -1,5 +1,5 @@
-.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.47.8.
-.TH BASE64URL "1" "February 2021" "base64url 0.7" "User Commands"
+.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.48.1.
+.TH BASE64URL "1" "March 2022" "base64url 0.9" "User Commands"
 .SH NAME
 base64url \- Base64Url encode or decode FILE, or standard input, to standard 
output.
 .SH SYNOPSIS
@@ -8,9 +8,9 @@
 .SH DESCRIPTION
 base64url \- Base64Url encode or decode FILE, or standard input, to standard 
output.
 .PP
-Version 0.7
+Version 0.9
 .SH COPYRIGHT
-Copyright 2021 Nicolas Mora <[email protected]>
+Copyright 2021\-2022 Nicolas Mora <[email protected]>
 .PP
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GPL 3
@@ -43,7 +43,7 @@
 output version information and exit
 .PP
 .br
-Copyright 2021 Nicolas Mora <[email protected]>
+Copyright 2021\-2022 Nicolas Mora <[email protected]>
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GPL 3
 .SH "SEE ALSO"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/orcania-2.2.1/tools/base64url/base64url.c 
new/orcania-2.2.2/tools/base64url/base64url.c
--- old/orcania-2.2.1/tools/base64url/base64url.c       2021-06-02 
13:42:40.000000000 +0200
+++ new/orcania-2.2.2/tools/base64url/base64url.c       2022-03-09 
22:23:46.000000000 +0100
@@ -2,7 +2,7 @@
  * 
  * base64url: Base64Url encode or decode FILE, or standard input, to standard 
output.
  * 
- * Copyright 2021 Nicolas Mora <[email protected]>
+ * Copyright 2021-2022 Nicolas Mora <[email protected]>
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU GENERAL PUBLIC LICENSE
@@ -26,7 +26,7 @@
 #include <ctype.h>
 #include <orcania.h>
 
-#define _BASE64URL_VERSION "0.7"
+#define _BASE64URL_VERSION "0.9"
 
 #define ACTION_ENCODE 0
 #define ACTION_DECODE 1
@@ -51,7 +51,7 @@
   fprintf(output, "\n");
   fprintf(output, "Version %s\n", _BASE64URL_VERSION);
   fprintf(output, "\n");
-  fprintf(output, "Copyright 2021 Nicolas Mora <[email protected]>\n");
+  fprintf(output, "Copyright 2021-2022 Nicolas Mora <[email protected]>\n");
   fprintf(output, "\n");
   fprintf(output, "This program is free software; you can redistribute it 
and/or\n");
   fprintf(output, "modify it under the terms of the GPL 3\n");
@@ -157,7 +157,7 @@
         break;
       case 'v':
         fprintf(stdout, "%s %s\n", argv[0], _BASE64URL_VERSION);
-        fprintf(stdout, "Copyright 2021 Nicolas Mora <[email protected]>\n");
+        fprintf(stdout, "Copyright 2021-2022 Nicolas Mora 
<[email protected]>\n");
         fprintf(stdout, "This program is free software; you can redistribute 
it and/or\n");
         fprintf(stdout, "modify it under the terms of the GPL 3\n");
         exit_loop = 1;

Reply via email to