(ns project.util (:require [[base64-clj.core :as b64]])) (defn b64-encode "Function for a safe base-64 encode that handels nils as well as converts any non-string argument to it's string equivalent and then encodes that. It's also smart enough to take a sequence of things and encode each, individually - returning a sequence of encoded values." [s] (cond (nil? s) nil (string? s) (b64/encode s) (coll? s) (map b64-encode s) :else (b64-encode (pr-str s)))) (defn b64-decode "Function to safely attempt to do a base64 decoding of the argument - assuming it's a correct fit for the decoding. It's got to be a string, and it's got to have a length that's divisible by 4. If it's invalid, this function will just return `nil`." [s] (cond (string? s) (let [len (count s)] (when (and (pos? len) (zero? (unchecked-remainder-int len 4))) (b64/decode s))) (coll? s) (map b64-decode s) :else nil))