Skip to content

Commit

Permalink
Merge 83d6b83 into b24f06a
Browse files Browse the repository at this point in the history
  • Loading branch information
f-f committed Oct 14, 2018
2 parents b24f06a + 83d6b83 commit 183b337
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/dhall_clj/fail.clj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
(ex/derive ::missing-file ::imports)
(ex/derive ::missing-imports ::imports)
(ex/derive ::cyclic-import ::imports)
(ex/derive ::hash-mismatch ::imports)

(defn missing-keyword!
"Throws an ex-info from the `missing` keyword"
Expand Down Expand Up @@ -88,6 +89,15 @@
{:type ::cyclic-import
:import import}))

(defn hash-mismatch!
"Throws an ex-info on hash protection mismatch"
[import actual-hash expression]
(throw-data
"Hash mismatch"
{:type ::hash-mismatch
:import import
:actual-hash actual-hash
:expression expression}))

;;
;; Serialization
Expand Down
16 changes: 14 additions & 2 deletions src/dhall_clj/import.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
[dhall-clj.parse :refer [parse expr]]
[dhall-clj.state :as state]
[dhall-clj.fail :as fail]
[dhall-clj.alpha-normalize :refer [alpha-normalize]]
[dhall-clj.binary :as binary]
[clojure.string :as str]
[dhall-clj.state :as s])
(:import [dhall_clj.ast Import Local Remote Env Missing]))
Expand Down Expand Up @@ -135,8 +137,18 @@
resolved-expr (resolve-imports
dynamic-expr
(update state :stack conj data))]
;; TODO: typecheck + normalize
resolved-expr))))
;; TODO: typecheck + normalize resolved-expr
(if-not hash?
resolved-expr
;; TODO TEST THIS
(let [expected-hash (str/lower-case hash?)
actual-hash (-> resolved-expr
alpha-normalize
binary/encode
sha-256)]
(if (= expected-hash actual-hash)
resolved-expr
(fail/hash-mismatch! this actual-hash resolved-expr))))))))

dhall_clj.ast.ImportAlt
(resolve-imports [this state]
Expand Down

0 comments on commit 183b337

Please sign in to comment.