Some cleanup for base64_encode

This commit is contained in:
bptato
2021-02-02 23:59:42 +01:00
parent e4570e8b6e
commit d277e80771
3 changed files with 10 additions and 6 deletions
+4 -4
View File
@@ -2008,7 +2008,7 @@ void (*mySignal(int signal_number, void (*action) (int))) (int) {
static char Base64Table[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const char *
char *
base64_encode(const unsigned char *src, int len)
{
unsigned char *w, *at;
@@ -2021,9 +2021,9 @@ base64_encode(const unsigned char *src, int len)
k = k / 3 * 4;
if (k < len)
return "";
return NULL;
w = GC_MALLOC_ATOMIC(k);
w = GC_MALLOC_ATOMIC(k + 1);
w[k] = 0;
at = w;
@@ -2061,5 +2061,5 @@ base64_encode(const unsigned char *src, int len)
*at++ = '=';
}
}
return w;
return (char *)w;
}
+5 -1
View File
@@ -1175,7 +1175,11 @@ AuthBasicCred(struct http_auth *ha, Str uname, Str pw, ParsedURL *pu,
Str s = Strdup(uname);
Strcat_char(s, ':');
Strcat(s, pw);
return Strnew_m_charp("Basic ", base64_encode(s->ptr, s->length), NULL);
char *base64 = base64_encode(s->ptr, s->length);
if (!base64)
return Strnew_charp("Basic ");
else
return Strnew_m_charp("Basic ", base64, NULL);
}
#ifdef USE_DIGEST_AUTH
+1 -1
View File
@@ -829,4 +829,4 @@ void srand48(long);
long lrand48(void);
#endif
extern const char *base64_encode(const unsigned char *src, int len);
extern char *base64_encode(const unsigned char *src, int len);