base64: Make alphabet and const uint8_t

Fixes T188

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Andreas Schneider
2019-10-31 16:28:53 +01:00
parent fe9991b3c6
commit fdb7cb8f17

View File

@@ -29,7 +29,8 @@
#include "libssh/priv.h" #include "libssh/priv.h"
#include "libssh/buffer.h" #include "libssh/buffer.h"
static char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" static
const uint8_t alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz"
"0123456789+/"; "0123456789+/";
@@ -171,15 +172,15 @@ error:
return NULL; return NULL;
} }
#define BLOCK(letter, n) do {ptr = strchr(alphabet, source[n]); \ #define BLOCK(letter, n) do {ptr = strchr((const char *)alphabet, source[n]); \
if(!ptr) return -1; \ if(!ptr) return -1; \
i = ptr - alphabet; \ i = ptr - (const char *)alphabet; \
SET_##letter(*block, i); \ SET_##letter(*block, i); \
} while(0) } while(0)
/* Returns 0 if ok, -1 if not (ie invalid char into the stuff) */ /* Returns 0 if ok, -1 if not (ie invalid char into the stuff) */
static int to_block4(unsigned long *block, const char *source, int num) { static int to_block4(unsigned long *block, const char *source, int num) {
char *ptr; const char *ptr = NULL;
unsigned int i; unsigned int i;
*block = 0; *block = 0;
@@ -234,9 +235,9 @@ static int get_equals(char *string) {
} }
/* thanks sysk for debugging my mess :) */ /* thanks sysk for debugging my mess :) */
static void _bin_to_base64(unsigned char *dest, static void _bin_to_base64(uint8_t *dest,
const unsigned char source[3], const uint8_t source[3],
int len) size_t len)
{ {
#define BITS(n) ((1 << (n)) - 1) #define BITS(n) ((1 << (n)) - 1)
switch (len) { switch (len) {