diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2023-10-16 22:04:41 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2023-10-16 22:04:41 (GMT) |
commit | cc53c9b1124b464556ba29a4a91a33628b3efe14 (patch) | |
tree | 36938b81248690a41fb3baa4e55a8dc643afdfc7 | |
parent | 015a0f3979b24f222317b305b056211515f9a64f (diff) |
Fix some bugs in the base64 implementation.
-rw-r--r-- | plugins/encodings/base64.c | 6 | ||||
-rw-r--r-- | plugins/encodings/python/Makefile.am | 3 | ||||
-rw-r--r-- | plugins/encodings/python/rost/Makefile.am | 3 | ||||
-rw-r--r-- | tests/plugins/encodings/all.py | 23 |
4 files changed, 31 insertions, 4 deletions
diff --git a/plugins/encodings/base64.c b/plugins/encodings/base64.c index 61b88e0..c749a87 100644 --- a/plugins/encodings/base64.c +++ b/plugins/encodings/base64.c @@ -54,8 +54,8 @@ bool _base64_encode(const sized_binary_t *input, sized_string_t *output, const s output->len = input->len * 4 / 3; - if (input->len % 3 != 0) - output->len++; + if (output->len % 4 != 0) + output->len += (4 - output->len % 4); output->data = malloc((output->len + 1) * sizeof(bin_t)); @@ -78,6 +78,8 @@ bool _base64_encode(const sized_binary_t *input, sized_string_t *output, const s *iter++ = alpha[src[i + 2] & 0x3f]; } + else + i = 0; /* Bourrage final ? */ diff --git a/plugins/encodings/python/Makefile.am b/plugins/encodings/python/Makefile.am index f999f9f..523a6f4 100644 --- a/plugins/encodings/python/Makefile.am +++ b/plugins/encodings/python/Makefile.am @@ -8,7 +8,8 @@ libencodingspython_la_SOURCES = \ libencodingspython_la_LIBADD = \ rost/libencodingspythonrost.la -libencodingspython_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ +libencodingspython_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS) \ + $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ -I$(top_srcdir)/src -DNO_IMPORT_PYGOBJECT diff --git a/plugins/encodings/python/rost/Makefile.am b/plugins/encodings/python/rost/Makefile.am index a5a2969..531fb26 100644 --- a/plugins/encodings/python/rost/Makefile.am +++ b/plugins/encodings/python/rost/Makefile.am @@ -5,7 +5,8 @@ libencodingspythonrost_la_SOURCES = \ base64.h base64.c \ module.h module.c -libencodingspythonrost_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ +libencodingspythonrost_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS) \ + $(LIBPYTHON_INTERPRETER_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ -I$(top_srcdir)/src -DNO_IMPORT_PYGOBJECT diff --git a/tests/plugins/encodings/all.py b/tests/plugins/encodings/all.py new file mode 100644 index 0000000..a856ccb --- /dev/null +++ b/tests/plugins/encodings/all.py @@ -0,0 +1,23 @@ + +from chrysacase import ChrysalideTestCase +from pychrysalide.plugins import encodings + +import base64 + + +class TestEncodingsModule(ChrysalideTestCase): + """TestCase for encodings plugin.""" + + def testBase64Encoding(self): + """Validate the base64 implementation.""" + + text = '0123456789abcdef' + + for i in range(len(text) + 1): + + src = text[:i].encode('ascii') + + encoded = encodings.base64_encode(src) + ref = base64.b64encode(src) + + self.assertEqual(encoded, ref) |