remove unused code, tidy string parsing
This commit is contained in:
parent
9041d5d63a
commit
41733e58d6
@ -13,23 +13,18 @@
|
|||||||
(pid status) (rshift (band status 0xff00) 8)
|
(pid status) (rshift (band status 0xff00) 8)
|
||||||
(nil errno) (error (.. "waitpid: " errno))))
|
(nil errno) (error (.. "waitpid: " errno))))
|
||||||
|
|
||||||
(fn min [a b] (if (< a b) a b))
|
|
||||||
|
|
||||||
(fn trace [s] (print :TRACE s) s)
|
|
||||||
|
|
||||||
(fn write-all [fd str]
|
(fn write-all [fd str]
|
||||||
(let [written (ll.write fd str)]
|
(let [written (ll.write fd str)]
|
||||||
(if (< written (# str))
|
(if (< written (# str))
|
||||||
(write-all fd (string.sub str (+ written 1) -1)))))
|
(write-all fd (string.sub str (+ written 1) -1)))))
|
||||||
|
|
||||||
|
|
||||||
(fn jose [params inputstr]
|
(fn jose [params inputstr]
|
||||||
(let [env (ll.environ)
|
(let [env (ll.environ)
|
||||||
(pid in out) (popen2 (os.getenv "JOSE_BIN") params env)]
|
(pid in out) (popen2 (os.getenv "JOSE_BIN") params env)]
|
||||||
;(print "exec " (os.getenv "JOSE_BIN") (view params))
|
;; be careful if using this code for commands othert than jose: it
|
||||||
;(print "writing")
|
;; may deadlock if we write more than 8k and the command doesn't
|
||||||
|
;; read it.
|
||||||
(when inputstr (write-all in inputstr))
|
(when inputstr (write-all in inputstr))
|
||||||
;(print :written)
|
|
||||||
(ll.close in)
|
(ll.close in)
|
||||||
(let [output
|
(let [output
|
||||||
(accumulate [o ""
|
(accumulate [o ""
|
||||||
@ -64,7 +59,7 @@
|
|||||||
(fn jwe-dec [jwk ph undigested]
|
(fn jwe-dec [jwk ph undigested]
|
||||||
(let [(exitcode plaintext)
|
(let [(exitcode plaintext)
|
||||||
(jose ["jose" "jwe" "dec" "-k-" "-i-"]
|
(jose ["jose" "jwe" "dec" "-k-" "-i-"]
|
||||||
(.. (json.encode jwk) ph undigested))]
|
(.. (json.encode jwk) ph "." undigested))]
|
||||||
(if (= exitcode 0)
|
(if (= exitcode 0)
|
||||||
plaintext
|
plaintext
|
||||||
(error (.. "Error calling jwe dec: " exitcode " / " plaintext )))))
|
(error (.. "Error calling jwe dec: " exitcode " / " plaintext )))))
|
||||||
@ -94,13 +89,10 @@
|
|||||||
"application/x-www-form-urlencoded"
|
"application/x-www-form-urlencoded"
|
||||||
body)))
|
body)))
|
||||||
|
|
||||||
|
|
||||||
(fn run []
|
(fn run []
|
||||||
(let [b64 (base64 :url)
|
(let [b64 (base64 :url)
|
||||||
raw (: (io.input) :read "*a")
|
raw (: (io.input) :read "*a")
|
||||||
dot (string.find raw "." 1 true)
|
(_ _ ph undigested) (string.find raw "(.-)%.(.+)")
|
||||||
ph (string.sub raw 1 dot)
|
|
||||||
undigested (string.sub raw (+ 1 dot) -1)
|
|
||||||
jwe (json.decode (b64:decode ph))
|
jwe (json.decode (b64:decode ph))
|
||||||
{ : srv : crv : clt : kid : url} (parse-jwe jwe)
|
{ : srv : crv : clt : kid : url} (parse-jwe jwe)
|
||||||
eph (jwk-generate crv)
|
eph (jwk-generate crv)
|
||||||
|
Loading…
Reference in New Issue
Block a user