changeset 746:7887fef9fcbe

base64: properly encode last group when only 2 bytes are left The RFC states that we should encode the group by adding zeroes on the right. We were accidentally adding them on the left. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Thu, 13 Jun 2019 00:16:51 +0300
parents 072420c8e932
children 18a6543019cb
files base64.c
diffstat 1 files changed, 2 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/base64.c	Thu Jun 13 00:10:36 2019 +0300
+++ b/base64.c	Thu Jun 13 00:16:51 2019 +0300
@@ -153,8 +153,8 @@
 			break;
 		case 2:
 			/* 2 bytes left - encoded them & pad with = */
-			v =  in[i * 3] << 8;
-			v |= in[i * 3 + 1];
+			v =  in[i * 3] << 10;
+			v |= in[i * 3 + 1] << 2;
 
 			out[i * 4]     = table[(v >> 12) & 0x3f];
 			out[i * 4 + 1] = table[(v >> 6) & 0x3f];