Commit 1edcf521 authored by Niels Möller's avatar Niels Möller

Fix remaining pointer-signedness warnings for base64.

* 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.
parent cfd07ba9
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
......
......@@ -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);
......
......@@ -40,6 +40,12 @@
#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;
......
......@@ -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"));
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment