Skip to content

Commit

Permalink
Use goog.crypt in internals.util-js in place of base64-js dependency …
Browse files Browse the repository at this point in the history
…and homebrew hex encode
  • Loading branch information
skinkade committed Aug 24, 2021
1 parent 7f20387 commit efc58a4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"dependencies": {
"base64-js": "^1.5.1",
"shadow-cljs": "^2.15.2"
}
}
15 changes: 6 additions & 9 deletions src/uniformity/internals/util_js.cljs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
(ns uniformity.internals.util-js
(:require [base64-js]
(:require [goog.crypt :refer [byteArrayToHex hexToByteArray]]
[goog.crypt.base64 :as base64]
[clojure.string :refer [replace]]))

(defn base64-encode [bytes]
(base64-js/fromByteArray bytes))
(base64/encodeByteArray bytes))

(defn base64-encode-urlsafe [bytes]
(-> bytes
Expand All @@ -23,19 +24,15 @@
(replace "-" "+")
(replace "_" "/")
(pad-base64))]
(base64-js/toByteArray string)))
(base64/decodeStringToUint8Array string)))

(defn byte->hex [byte]
(-> byte
(.toString 16)
(.padStart 2 "0")))

(defn hex-encode [bytes]
(apply str (map byte->hex bytes)))
(byteArrayToHex bytes))

(defn hex-decode [string]
(->> string
(partition 2)
(map #(apply str %))
(map #(js/parseInt % 16))
(.from js/Uint8Array)))
(hexToByteArray string))

0 comments on commit efc58a4

Please sign in to comment.