-
Notifications
You must be signed in to change notification settings - Fork 6
/
jws.cljc
30 lines (23 loc) · 1.03 KB
/
jws.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(ns axel-f.excel.jws
(:require [axel-f.buddy.jws :as jws]
[clojure.string :as string]
[axel-f.buddy.codecs :as codecs]))
(defn jws-sign*
"Sign arbitrary payload as a string using one of supported algorythms: HS256, HS384, HS512"
[alg payload & opts]
(jws/sign payload (first opts) :alg (keyword (string/lower-case alg))))
(def jws-sign #'jws-sign*)
(defn jws-extract*
"Extract payload as a string from Web Signature using one of supported algorythms: HS256, HS384, HS512"
[alg payload & opts]
(codecs/to-string (jws/extract payload (first opts) :alg (keyword (string/lower-case alg)))))
(def jws-extract #'jws-extract*)
(defn jws-verify*
"Verify the signature of the payload and extract its content as a string"
[alg payload & opts]
(let [{:strs [error] :as res} (jws/verify payload (first opts) :alg (keyword (string/lower-case alg)))]
(if error res (update res "payload" codecs/to-string))))
(def jws-verify #'jws-verify*)
(def env
{"JWS" {"EXTRACT" jws-extract
"VERIFY" jws-verify}})