Skip to content

Commit

Permalink
Adding buddy.hashers (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
judepayne authored Mar 10, 2023
1 parent 5b54ccf commit 0371029
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.3.4

- Add support for [buddy.hashers](https://github.com/funcool/buddy-hashers)

## v0.3.3

- Add support for buddy.core.crypto ([@iarenaza](https://github.com/iarenaza))
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## API

This pod uses the namespace scheme `buddy.x` -> `pod.babashka.buddy.x`.
For buddy's documentation, go [here](https://funcool.github.io/buddy-core/latest/api/index.html).
For buddy's documentation, go [here](https://funcool.github.io/buddy-core/latest/api/index.html) and
[here](https://funcool.github.io/buddy-hashers/latest/user-guide.html) for buddy-hashers.

Available namespaces:

Expand All @@ -17,6 +18,7 @@ Available namespaces:
- `pod.babashka.buddy.sign.jwe`
- `pod.babashka.buddy.sign.jws`
- `pod.babashka.buddy.sign.jwt`
- `pod.babashka.buddy.hashers`

If you are missing functionality, please create an issue.

Expand Down Expand Up @@ -115,6 +117,11 @@ a encoded byte-array of the key. The affected functions are:
- `encrypt`
- `decrypt`

### Hashers
The `derive` and `verify` functions are exposed. Remember to set the `:salt` in
the options map supplied to `derive` or you'll get a different hash each time.


## Example

``` clojure
Expand Down
3 changes: 2 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{:deps {com.cognitect/transit-clj {:mvn/version "1.0.329"}
buddy/buddy-core {:mvn/version "1.10.413"}
buddy/buddy-sign {:mvn/version "3.4.333"}
buddy/buddy-hashers {:mvn/version "1.8.158"}
nrepl/bencode {:mvn/version "1.1.0"}
babashka/pods {:git/url "https://github.com/babashka/pods"
:git/sha "93081b75e66fb4c4d161f89e714c6b9e8d55c8d5"}}
Expand All @@ -13,5 +14,5 @@
com.github.clj-easy/graal-build-time {:mvn/version "0.1.4"}}}

:build ;; added by neil
{:deps {io.github.clojure/tools.build {:git/tag "v0.8.3" :git/sha "0d20256"}}
{:deps {io.github.clojure/tools.build {:git/tag "v0.9.4" :git/sha "76b78fe"}}
:ns-default build}}}
12 changes: 11 additions & 1 deletion reflection-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,15 @@
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allPublicMethods" : true
},
{
"name" : "org.bouncycastle.crypto.digests.SHA256Digest",
"allPublicConstructors" : true,
"allPublicMethods" : true
},
{
"name" : "org.bouncycastle.crypto.params.KeyParameter",
"allPublicConstructors" : true,
"allPublicMethods" : true
}
]
]
2 changes: 1 addition & 1 deletion resources/POD_BABASHKA_BUDDY_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.3
0.3.4
12 changes: 12 additions & 0 deletions src/pod/babashka/buddy.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[buddy.core.hash :as hash]
[buddy.core.mac :as mac]
[buddy.core.nonce :as nonce]
[buddy.hashers :as hashers]
[pod.babashka.buddy.crypto :as crypto]
[pod.babashka.buddy.kdf :as kdf]
[pod.babashka.buddy.jws :as pjws]
Expand Down Expand Up @@ -83,6 +84,11 @@
:core/nonce
{'random-bytes nonce/random-bytes
'random-nonce nonce/random-nonce}
:core/hashers
{'derive hashers/derive
'encrypt hashers/encrypt
'check hashers/check
'verify hashers/verify}
:core/codecs
{'bytes->hex codecs/bytes->hex
'bytes->long codecs/bytes->long
Expand Down Expand Up @@ -140,6 +146,8 @@
(:core/nonce nses)
'pod.babashka.buddy.core.nonce
(:core/nonce nses)
'pod.babashka.buddy.hashers
(:core/hashers nses)
'pod.babashka.buddy.codecs
(:core/codecs nses)
'pod.babashka.buddy.core.codecs
Expand Down Expand Up @@ -198,6 +206,10 @@
:vars ~(mapv (fn [[k _]]
{:name k})
(get lookup* 'pod.babashka.buddy.core.nonce))}
{:name pod.babashka.buddy.hashers
:vars ~(mapv (fn [[k _]]
{:name k})
(get lookup* 'pod.babashka.buddy.hashers))}
{:name pod.babashka.buddy.codecs
:vars ~(mapv (fn [[k _]]
{:name k})
Expand Down
11 changes: 11 additions & 0 deletions test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,14 @@
(when-not (= "executable" (System/getProperty "org.graalvm.nativeimage.kind"))
(shutdown-agents)
(System/exit 0))

;; -- Hashers Tests --
(require '[pod.babashka.buddy.hashers :as hashers])

(def salt16 "f0168195ebd8eb214e535d6793ae31be")
(def hash-pbkdf2 "pbkdf2+sha256$6630313638313935656264386562323134653533356436373933616533316265$100000$417bbe0e252343550ff15cb5d5b87b6a539f4905a96a9fdaa9f2805416670f98")

(assert (= hash-pbkdf2
(hashers/derive "SECRET PASSWORD!" {:salt salt16 :alg :pbkdf2+sha256})))

(assert (true? (:valid (hashers/verify "SECRET PASSWORD!" hash-pbkdf2))))

0 comments on commit 0371029

Please sign in to comment.