It appears that the BASE64-ENCODE function was written only for strings. If one has an array of type (UNSIGNED-BYTE 8) to send encoded, this function doesn't work properly. Here is a suggested replacement for that function.
For backwards compatibility, it takes strings and converts them (using CHAR-CODE) to arrays of (UNSIGNED-BYTE 8) before processing. However, it seems odd that you'd encode a regular string rather than just not encoding it.
(defun base64-encode (array)
;;
;; take the given string and encode as a base64 string
;; beware: the result will not be a simple string
;;
(let ((output (make-array 20
:element-type 'character
:fill-pointer 0
:adjustable t))
v1 v2 v3 eol
(from 0)
(max (length array))
)
(when (typep array 'string)
(let ((new-array (make-array (length array) :element-type '(unsigned-byte\
8))))
(loop for i below (length array)
do (setf (aref new-array i) (char-code (char array i))))
(setq array new-array)))
(loop
(if* (>= from max)
then (return))
(setq v1 (aref array from))
(incf from)
(if* (>= from max)
then (setq v2 0
eol t)
else (setq v2 (aref array from)))
(incf from)
; put out first char of encoding
(vector-push-extend (schar *base64-encode* (logand #x3f
(ash v1 -2)))
output)
; put out second char of encoding
(vector-push-extend (schar *base64-encode*
(+ (ash (logand 3 v1) 4)
(logand #xf (ash v2 -4))))
output)
(if* eol
then ; two pads
(vector-push-extend #\= output)
(vector-push-extend #\= output)
(return))
(if* (>= from max)
then (setq v3 0
eol t)
else (setq v3 (aref array from)))
(incf from)
; put out third char of encoding
(vector-push-extend (schar *base64-encode*
(+ (ash (logand #xf v2) 2)
(logand 3 (ash v3 -6))))
output)
(if* eol
then (vector-push-extend #\= output)
(return))
; put out fourth char of encoding
(vector-push-extend (schar *base64-encode* (logand #x3f v3))
output))
output))
Let me think about this a bit.
The purpose of that function was to support Basic Authorization. There, in my opinion, the base64 encoding is done (rather than normal urlencoding) in order to add a bit of security to the information transmitted (admittedly it's not much security).
Thus the base64 encoder in aserve was designed to just handle this. I'll look into the binary version.
Since this must work in a 16 bit character lisp it gets tricky dealing with the conversion between characters and binary data.