aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/dependency.lux
diff options
context:
space:
mode:
authorEduardo Julian2020-10-15 01:01:21 -0400
committerEduardo Julian2020-10-15 01:01:21 -0400
commitc006a5fe8e82f6fc7c8cdb9db0f44c06d229f34e (patch)
treef00af06ceb7cd77ab53aa214abb2e7383dc87500 /stdlib/source/program/aedifex/dependency.lux
parent440608bc32916329c9f3c0f2bd9a8d1152ed5da8 (diff)
Re-named "to-text" functions to "format".
Diffstat (limited to 'stdlib/source/program/aedifex/dependency.lux')
-rw-r--r--stdlib/source/program/aedifex/dependency.lux54
1 files changed, 12 insertions, 42 deletions
diff --git a/stdlib/source/program/aedifex/dependency.lux b/stdlib/source/program/aedifex/dependency.lux
index 52a1f00c5..de6a1e4cf 100644
--- a/stdlib/source/program/aedifex/dependency.lux
+++ b/stdlib/source/program/aedifex/dependency.lux
@@ -2,6 +2,7 @@
[lux (#- Name)
["." host (#+ import:)]
[abstract
+ [codec (#+ Codec)]
[monad (#+ do)]
["." equivalence (#+ Equivalence)]
["." hash (#+ Hash)]]
@@ -93,40 +94,6 @@
[chunk (:: io.monad wrap (binary.slice 0 (.nat bytes-read) buffer))]
(recur (:: binary.monoid compose output chunk)))))))))
-(def: hex-per-byte
- 2)
-
-(def: hex-per-nat
- (n.* hex-per-byte i64.bytes-per-i64))
-
-(type: Hash-Reader
- (-> Binary (Try //hash.Hash)))
-
-(def: (sha1 input)
- Hash-Reader
- (do try.monad
- [input (encoding.from-utf8 input)
- [left input] (try.from-maybe (text.split ..hex-per-nat input))
- [middle right] (try.from-maybe (text.split ..hex-per-nat input))
- #let [output (:: binary.monoid identity)]
- left (:: n.hex decode left)
- output (binary.write/64 0 left output)
- middle (:: n.hex decode middle)
- output (binary.write/64 i64.bytes-per-i64 middle output)
- right (:: n.hex decode right)]
- (binary.write/64 (n.* 2 i64.bytes-per-i64) right output)))
-
-(def: (md5 input)
- Hash-Reader
- (do try.monad
- [input (encoding.from-utf8 input)
- [left right] (try.from-maybe (text.split ..hex-per-nat input))
- #let [output (:: binary.monoid identity)]
- left (:: n.hex decode left)
- output (binary.write/64 0 left output)
- right (:: n.hex decode right)]
- (binary.write/64 i64.bytes-per-i64 right output)))
-
(template [<name>]
[(exception: #export (<name> {dependency Dependency} {hash Text})
(let [artifact (get@ #artifact dependency)
@@ -149,18 +116,21 @@
#sha1 Text
#md5 Text})
-(def: (verified-hash dependency library url hash reader exception)
- (-> Dependency Binary URL (-> Binary //hash.Hash) Hash-Reader (Exception [Dependency Text])
- (IO (Try Text)))
+(def: (verified-hash dependency library url hash codec exception)
+ (All [h]
+ (-> Dependency Binary URL
+ (-> Binary (//hash.Hash h)) (Codec Text (//hash.Hash h))
+ (Exception [Dependency Text])
+ (IO (Try Text))))
(do (try.with io.monad)
- [#let [reference (hash library)]
+ [#let [expected (hash library)]
actual (..download url)]
(:: io.monad wrap
(do try.monad
[output (encoding.from-utf8 actual)
- actual (reader actual)
+ actual (:: codec decode output)
_ (exception.assert exception [dependency output]
- (:: binary.equivalence = reference actual))]
+ (:: //hash.equivalence = expected actual))]
(wrap output)))))
(def: parse-property
@@ -220,8 +190,8 @@
prefix (format repository uri.separator (//artifact.path artifact))]
(do (try.with io.monad)
[library (..download (format prefix (//artifact/extension.extension type)))
- sha1 (..verified-hash dependency library (format prefix //artifact/extension.sha1) //hash.sha1 ..sha1 ..sha1-does-not-match)
- md5 (..verified-hash dependency library (format prefix //artifact/extension.md5) //hash.md5 ..md5 ..md5-does-not-match)
+ sha1 (..verified-hash dependency library (format prefix //artifact/extension.sha1) //hash.sha1 //hash.sha1-codec ..sha1-does-not-match)
+ md5 (..verified-hash dependency library (format prefix //artifact/extension.md5) //hash.md5 //hash.md5-codec ..md5-does-not-match)
pom (..download (format prefix //artifact/extension.pom))]
(:: io.monad wrap
(do try.monad