From 0099af525fe5efed85b27274d2341962b3929dae Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Fri, 6 Dec 2013 19:01:10 +0100 Subject: fixes in base64 encode and auth structure --- picohttp.c | 5 ++++- picohttp_base64.c | 22 ++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/picohttp.c b/picohttp.c index d813a3e..bfce031 100644 --- a/picohttp.c +++ b/picohttp.c @@ -826,7 +826,10 @@ static void picohttpProcessHeaderAuthorization( /* invalid chunk => abort the whole header */ return; } - for(size_t j=0; j < l && i < user_password_max_len; j++, i++) { + for(size_t j=0; + j < l + && i < user_password_max_len; + j++, i++) { user_password[i] = r[j]; } } diff --git a/picohttp_base64.c b/picohttp_base64.c index 1374bff..3411286 100644 --- a/picohttp_base64.c +++ b/picohttp_base64.c @@ -5,24 +5,22 @@ void phb64encode( size_t count, phb64enc_t enc) { - switch(count) { - default: break; - case 2: - enc[3] = 0xff; - case 1: - enc[2] = 0xff; - } + enc[1] = 0; + enc[3] = 0xff; + enc[2] = (count > 1) ? 0 : 0xff; + switch(count) { default: return; - case 4: - enc[3] |= ((raw[3] & 0x3f)); case 3: + enc[3] = ((raw[2] & 0x3f)); + enc[2] = ((raw[2] & 0xc0) >> 6); case 2: - enc[2] |= ((raw[2] & 0xc0) >> 6) | ((raw[1] & 0x0f) << 2); + enc[2] |= ((raw[1] & 0x0f) << 2); + enc[1] = ((raw[1] & 0xf0) >> 4); case 1: - enc[1] = ((raw[1] & 0xf0) >> 4) | ((raw[0] & 0x03) << 4); - enc[0] = ((raw[0] & 0xfc) >> 2); + enc[1] |= ((raw[0] & 0x03) << 4); + enc[0] = ((raw[0] & 0xfc) >> 2); } for(int i = 0; i < 4; i++) { -- cgit v1.2.3