From c006a5fe8e82f6fc7c8cdb9db0f44c06d229f34e Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 15 Oct 2020 01:01:21 -0400 Subject: Re-named "to-text" functions to "format". --- stdlib/source/program/aedifex/dependency.lux | 54 +++++++--------------------- 1 file changed, 12 insertions(+), 42 deletions(-) (limited to 'stdlib/source/program/aedifex/dependency.lux') 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 [] [(exception: #export ( {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 -- cgit v1.2.3