       (codecs/bytes->safebase64)))
 
 (defn- make-claims
-  "Make jws claims as json string"
+  "Encode jws claims."
   [input exp nbf iat]
   (-> (normalize-nil-claims {:exp exp :nbf nbf :iat iat})
       (normalize-date-claims)

      (codecs/bytes->safebase64)))

(defn- parse-header
  [headerdata]
  (-> headerdata
      (codecs/safebase64->bytes)
      (codecs/bytes->str)
      (json/parse-string true)))

(defn- parse-claims
  [claimsdata]
  (-> claimsdata
      (codecs/safebase64->bytes)
      (codecs/bytes->str)
      (json/parse-string true)))

(defn- parse-algorithm
  [header]
  (let [algname (:alg header)]
    (keyword (.toLowerCase algname))))

(defn- get-verifier-for-algorithm
  [^Keyword alg]
  (when (contains? gsign/*signers-map* alg)
    (get-in gsign/*signers-map* [alg :verifier])))

(defn- get-signer-for-algorith
  [^Keyword alg]
  (when (contains? gsign/*signers-map* alg)
    (get-in gsign/*signers-map* [alg :signer])))

(defn- safe-encode
  [input]
  (-> input
      (codecs/str->bytes)
      (codecs/bytes->safebase64)))

(defn- make-signature
  [pkey alg header claims]
  (let [candidate (str/join "." [header claims])
        signer    (get-signer-for-algorith alg)]
    (-> (signer candidate pkey)
        (codecs/bytes->safebase64))))


                        (or (< (- now (:iat claims)) maxage) nil)
                        true)]
          claims)))))
