about summary refs log tree commit diff
path: root/web/panettone/src/util.lisp
blob: 2abedf7b8fbbba0ab1a59f355f782a47437ce042 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(in-package :panettone.util)

(defun integer-env (var &key default)
  (or
   (when-let ((str (uiop:getenvp var)))
     (try-parse-integer str))
   default))

(defun add-missing-base64-padding (s)
  "Add any missing padding characters to the (un-padded) base64 string `S', such
that it can be successfully decoded by the `BASE64' package"
  ;; I apologize
  (let* ((needed-padding (mod (length s) 4))
         (pad-chars (if (zerop needed-padding) 0 (- 4 needed-padding))))
    (format nil "~A~v@{~A~:*~}" s pad-chars "=")))