Skip to content

Commit

Permalink
Remove dependency on crypto-random
Browse files Browse the repository at this point in the history
Remove crypto-random dependency and transitive dependency commons-codec
in order to make this library compatible with Babashka.
  • Loading branch information
mathaeussanderosp authored and Mathaeus Sander committed Oct 21, 2024
1 parent 00f19ae commit 4e226df
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.9.0"}
crypto-equality/crypto-equality {:mvn/version "1.0.1"}
hiccup/hiccup {:mvn/version "1.0.5"}}}
1 change: 0 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
:license {:name "The MIT License"
:url "http://opensource.org/licenses/MIT"}
:dependencies [[org.clojure/clojure "1.9.0"]
[crypto-random "1.2.1"]
[crypto-equality "1.0.1"]
[hiccup "1.0.5"]]
:plugins [[lein-codox "0.10.8"]]
Expand Down
12 changes: 9 additions & 3 deletions src/ring/middleware/anti_forgery/session.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
(ns ring.middleware.anti-forgery.session
"Contains the synchronizer token (or session) strategy."
(:require [ring.middleware.anti-forgery.strategy :as strategy]
[crypto.equality :as crypto]
[crypto.random :as random]))
[crypto.equality :as crypto]))

(defn- random-base64 [buffer-size]
(let [random (java.security.SecureRandom.)
base64 (.withoutPadding (java.util.Base64/getUrlEncoder))
buffer (byte-array buffer-size)]
(.nextBytes random buffer)
(.encodeToString base64 buffer)))

(defn- session-token [request]
(get-in request [:session :ring.middleware.anti-forgery/anti-forgery-token]))
Expand All @@ -11,7 +17,7 @@
strategy/Strategy
(get-token [this request]
(or (session-token request)
(random/base64 60)))
(random-base64 60)))

(valid-token? [_ request token]
(when-let [stored-token (session-token request)]
Expand Down

0 comments on commit 4e226df

Please sign in to comment.