about summary refs log tree commit diff
path: root/web/panettone/src
diff options
context:
space:
mode:
Diffstat (limited to 'web/panettone/src')
-rw-r--r--web/panettone/src/authentication.lisp8
-rw-r--r--web/panettone/src/packages.lisp2
-rw-r--r--web/panettone/src/util.lisp8
3 files changed, 10 insertions, 8 deletions
diff --git a/web/panettone/src/authentication.lisp b/web/panettone/src/authentication.lisp
index 5c6d82e02027..3ce07aa8d78d 100644
--- a/web/panettone/src/authentication.lisp
+++ b/web/panettone/src/authentication.lisp
@@ -78,12 +78,6 @@ the user, however email addresses are temporarily not available."
      ;; TODO(tazjin): Figure out actual displayName mapping in tokens.
      :displayname username)))
 
-(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
-  (format nil "~A~v@{~A~:*~}" s (- 4 (mod (length s) 4)) "="))
-
 (defun fetch-token (code)
   "Fetches the access token on completion of user authentication through
 the OAuth2 endpoint and returns the resulting user object."
@@ -117,5 +111,5 @@ the OAuth2 endpoint and returns the resulting user object."
                            ;; lisp base64 library doesn't know how to deal with
                            ;; that - we need to add those extra padding
                            ;; characters here.
-                           (add-missing-base64-padding payload)))))
+                           (panettone.util:add-missing-base64-padding payload)))))
             (claims-to-user claims))))))
diff --git a/web/panettone/src/packages.lisp b/web/panettone/src/packages.lisp
index a63f4c766a1c..4ff4c070f087 100644
--- a/web/panettone/src/packages.lisp
+++ b/web/panettone/src/packages.lisp
@@ -1,7 +1,7 @@
 (defpackage panettone.util
   (:use :cl :klatre)
   (:import-from :alexandria :when-let)
-  (:export :integer-env))
+  (:export :integer-env :add-missing-base64-padding))
 
 (defpackage panettone.css
   (:use :cl :lass)
diff --git a/web/panettone/src/util.lisp b/web/panettone/src/util.lisp
index 9fd9ceaa79a4..2abedf7b8fbb 100644
--- a/web/panettone/src/util.lisp
+++ b/web/panettone/src/util.lisp
@@ -5,3 +5,11 @@
    (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 "=")))