From 478eaea98213c13146c233560756608d281e15fa Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 26 Feb 2026 10:55:27 +0000 Subject: [PATCH] Update base64 compat. --- compat.h | 2 +- compat/base64.c | 34 ++++++++++++++-------------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/compat.h b/compat.h index 76ef70df..55fbad48 100644 --- a/compat.h +++ b/compat.h @@ -388,7 +388,7 @@ int clock_gettime(int, struct timespec *); /* base64.c */ #undef b64_ntop #undef b64_pton -int b64_ntop(const char *, size_t, char *, size_t); +int b64_ntop(const u_char *, size_t, char *, size_t); int b64_pton(const char *, u_char *, size_t); #endif diff --git a/compat/base64.c b/compat/base64.c index e90696df..d6dc6b96 100644 --- a/compat/base64.c +++ b/compat/base64.c @@ -1,4 +1,4 @@ -/* $OpenBSD: base64.c,v 1.8 2015/01/16 16:48:51 deraadt Exp $ */ +/* $OpenBSD: base64.c,v 1.15 2021/10/25 14:41:09 jca Exp $ */ /* * Copyright (c) 1996 by Internet Software Consortium. @@ -46,15 +46,15 @@ #include #include #include -#include #include #include -#include #include #include +#include "compat.h" + static const char Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const char Pad64 = '='; @@ -107,9 +107,9 @@ static const char Pad64 = '='; end of the data is performed using the '=' character. Since all base64 input is an integral number of octets, only the - ------------------------------------------------- + ------------------------------------------------- following cases can arise: - + (1) the final quantum of encoding input is an integral multiple of 24 bits; here, the final unit of encoded output will be an integral multiple of 4 characters @@ -123,15 +123,12 @@ static const char Pad64 = '='; */ int -b64_ntop(src, srclength, target, targsize) - u_char const *src; - size_t srclength; - char *target; - size_t targsize; +b64_ntop(unsigned char const *src, size_t srclength, char *target, + size_t targsize) { size_t datalength = 0; - u_char input[3]; - u_char output[4]; + unsigned char input[3]; + unsigned char output[4]; int i; while (2 < srclength) { @@ -152,14 +149,14 @@ b64_ntop(src, srclength, target, targsize) target[datalength++] = Base64[output[2]]; target[datalength++] = Base64[output[3]]; } - + /* Now we worry about padding. */ if (0 != srclength) { /* Get what's left. */ input[0] = input[1] = input[2] = '\0'; for (i = 0; i < srclength; i++) input[i] = *src++; - + output[0] = input[0] >> 2; output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); @@ -187,13 +184,10 @@ b64_ntop(src, srclength, target, targsize) */ int -b64_pton(src, target, targsize) - char const *src; - u_char *target; - size_t targsize; +b64_pton(char const *src, unsigned char *target, size_t targsize) { int tarindex, state, ch; - u_char nextbyte; + unsigned char nextbyte; char *pos; state = 0; @@ -207,7 +201,7 @@ b64_pton(src, target, targsize) break; pos = strchr(Base64, ch); - if (pos == 0) /* A non-base64 character. */ + if (pos == 0) /* A non-base64 character. */ return (-1); switch (state) {