]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Fix remaining pointer-signedness warnings for base64.
authorNiels Möller <nisse@lysator.liu.se>
Sun, 24 Sep 2017 11:33:46 +0000 (13:33 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Sun, 24 Sep 2017 11:33:46 +0000 (13:33 +0200)
* sexp-transport-format.c (base64_encode_in_place): New helper
function.
(sexp_transport_vformat): Use it.

* testsuite/base64-test.c (test_fuzz_once): Update to use char
type where appropriate.
(test_main): Use helper functions base64_encode_in_place and
base64_decode_in_place (copied to this file).

* tools/pkcs1-conv.c (base64_decode_in_place): New helper
function.
(decode_base64): Use it.

ChangeLog
base64.h
sexp-transport-format.c
testsuite/base64-test.c
tools/pkcs1-conv.c

index 6da59bd36f7c512e7c03ae38dee239b0c63bf129..28460864e9f0db6f4520e108c43d1fe301e1f5f6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2017-09-24  Niels Möller  <nisse@lysator.liu.se>
 
+       * tools/pkcs1-conv.c (base64_decode_in_place): New helper
+       function.
+       (decode_base64): Use it.
+
+       * sexp-transport-format.c (base64_encode_in_place): New helper
+       function.
+       (sexp_transport_vformat): Use it.
+
+       * testsuite/base64-test.c (test_fuzz_once): Update to use char
+       type where appropriate.
+       (test_main): Use helper functions base64_encode_in_place and
+       base64_decode_in_place (copied to this file).
+
        * testsuite/testutils.c (tstring_data): Use uint8_t for data
        argument.
        * testsuite/testutils.h (SDATA): Use US macro to cast data
index a6cac86067644b2f6d6865af3564a16f0eca5c06..8e69adb1dbe916488d04054231ccc7ae0e7f0839 100644 (file)
--- a/base64.h
+++ b/base64.h
@@ -110,7 +110,9 @@ base64_encode_final(struct base64_encode_ctx *ctx,
 
 /* Encodes a string in one go, including any padding at the end.
  * Generates exactly BASE64_ENCODE_RAW_LENGTH(length) bytes of output.
- * Supports overlapped operation, if src <= dst. */
+ * Supports overlapped operation, if src <= dst. FIXME: Use of overlap
+ * is deprecated, if needed there should be a separate public fucntion
+ * to do that.*/
 void
 base64_encode_raw(char *dst, size_t length, const uint8_t *src);
 
index 70de1c03e4f531539f892ad0d7658bc70d7521d0..4f83f8888c8abab42088da8a17f83e34696fdc0b 100644 (file)
 #include "base64.h"
 #include "buffer.h"
 
+static inline void
+base64_encode_in_place (size_t length, uint8_t *data)
+{
+  base64_encode_raw ((char *) data, length, data);
+}
+
 size_t
 sexp_transport_vformat(struct nettle_buffer *buffer,
                       const char *format, va_list args)
@@ -68,8 +74,7 @@ sexp_transport_vformat(struct nettle_buffer *buffer,
       if (!nettle_buffer_space(buffer, base64_length - length))
        return 0;
 
-      base64_encode_raw((char*) (buffer->contents + start),
-                       length, buffer->contents + start);
+      base64_encode_in_place(length, buffer->contents + start);
       
       if (!NETTLE_BUFFER_PUTC(buffer, '}'))
        return 0;
index f366a413843731a19916e1d9121831e2f993e809..cc45c471459ceda266938ecddc901ef36153bb7d 100644 (file)
@@ -9,7 +9,7 @@ test_fuzz_once(struct base64_encode_ctx *encode,
 {
   size_t base64_len = BASE64_ENCODE_RAW_LENGTH (size);
   size_t out_len;
-  uint8_t *base64 = xalloc (base64_len + 2);
+  char *base64 = xalloc (base64_len + 2);
   uint8_t *decoded = xalloc (size + 2);
 
   *base64++ = 0x12;
@@ -66,6 +66,20 @@ test_fuzz(void)
     }
 }
 
+static inline void
+base64_encode_in_place (size_t length, uint8_t *data)
+{
+  base64_encode_raw ((char *) data, length, data);
+}
+
+static inline int
+base64_decode_in_place (struct base64_decode_ctx *ctx, size_t *dst_length,
+                       size_t length, uint8_t *data)
+{
+  return base64_decode_update (ctx, dst_length,
+                              data, length, (const char *) data);
+}
+
 void
 test_main(void)
 {
@@ -111,12 +125,12 @@ test_main(void)
     size_t dst_length;
     
     ASSERT(BASE64_ENCODE_RAW_LENGTH(5) == 8);
-    base64_encode_raw(buffer, 5, buffer);
+    base64_encode_in_place(5, buffer);
     ASSERT(MEMEQ(9, buffer, "SGVsbG8=x"));
 
     base64_decode_init(&ctx);
     dst_length = 0; /* Output parameter only. */
-    ASSERT(base64_decode_update(&ctx, &dst_length, buffer, 8, buffer));
+    ASSERT(base64_decode_in_place(&ctx, &dst_length, 8, buffer));
     ASSERT(dst_length == 5);
     
     ASSERT(MEMEQ(9, buffer, "HelloG8=x"));
index c8697c445dc5c2a74258a93400e90eaaf799aba4..efd6528a4ab4401f73a30f48603752723cc5ef32 100644 (file)
@@ -244,6 +244,14 @@ read_pem(struct nettle_buffer *buffer, FILE *f,
     }
 }
 
+static inline int
+base64_decode_in_place (struct base64_decode_ctx *ctx, size_t *dst_length,
+                       size_t length, uint8_t *data)
+{
+  return base64_decode_update (ctx, dst_length,
+                              data, length, (const char *) data);
+}
+
 static int
 decode_base64(struct nettle_buffer *buffer,
              size_t start, size_t *length)
@@ -253,9 +261,8 @@ decode_base64(struct nettle_buffer *buffer,
   base64_decode_init(&ctx);
 
   /* Decode in place */
-  if (base64_decode_update(&ctx,
-                          length, buffer->contents + start,
-                          *length, (const char *) buffer->contents + start)
+  if (base64_decode_in_place(&ctx, length,
+                            *length, buffer->contents + start)
       && base64_decode_final(&ctx))
     return 1;