🎉 Add "sodi" vendor library for crypto primitives.

Will replace buddy-core, buddy-hashers and buddy-sign.
This commit is contained in:
Andrey Antukh 2020-01-12 18:58:00 +00:00
parent 193c2026ba
commit fe2c3aa8ad
8 changed files with 652 additions and 0 deletions

View file

@ -0,0 +1,22 @@
(ns sodi.tests.test-pwhash
(:require
[clojure.test :as t]
[clojure.test.check.clojure-test :refer [defspec]]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as props]
[sodi.pwhash :as pwh]))
(defspec derive-verify-roundtrip 1000
(props/for-all
[password gen/string]
(let [pwhash (pwh/derive password {:cpucost 10})
result (pwh/verify password pwhash)]
(t/is (true? (:valid result))))))
(defspec derive-verify-roundtrip-invalid 1000
(props/for-all
[pw1 gen/string
pw2 (gen/such-that #(not= % pw1) gen/string)]
(let [pwhash (pwh/derive pw1 {:cpucost 10})
result (pwh/verify pw2 pwhash)]
(t/is (false? (:valid result))))))

31
backend/vendor/sodi/tests/user.clj vendored Normal file
View file

@ -0,0 +1,31 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; This Source Code Form is "Incompatible With Secondary Licenses", as
;; defined by the Mozilla Public License, v. 2.0.
;;
;; Copyright (c) 2020 Andrey Antukh <niwi@niwi.nz>
(ns user
(:require
[clojure.tools.namespace.repl :as repl]
[clojure.walk :refer [macroexpand-all]]
[clojure.pprint :refer [pprint]]
[clojure.test :as test]
[clojure.java.io :as io]
[clojure.repl :refer :all]))
(defn run-tests
([] (run-tests #"^sodi.tests.*"))
([o]
;; (repl/refresh)
(cond
(instance? java.util.regex.Pattern o)
(test/run-all-tests o)
(symbol? o)
(if-let [sns (namespace o)]
(do (require (symbol sns))
(test/test-vars [(resolve o)]))
(test/test-ns o)))))