diff options
Diffstat (limited to 'stdlib/source/program/aedifex/hash.lux')
-rw-r--r-- | stdlib/source/program/aedifex/hash.lux | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/stdlib/source/program/aedifex/hash.lux b/stdlib/source/program/aedifex/hash.lux index bd4396006..63511a74d 100644 --- a/stdlib/source/program/aedifex/hash.lux +++ b/stdlib/source/program/aedifex/hash.lux @@ -2,7 +2,11 @@ [lux #* ["." host (#+ import:)] [data - ["." binary (#+ Binary)]]]) + ["." binary (#+ Binary)] + ["." text + ["%" format (#+ format)]] + [number + ["." nat]]]]) ## TODO: Replace with pure-Lux implementations of these algorithms ## https://en.wikipedia.org/wiki/SHA-1#SHA-1_pseudocode @@ -25,3 +29,13 @@ [sha1 "SHA-1"] [md5 "MD5"] ) + +(def: #export representation + (-> Hash Text) + (binary.fold (function (_ byte representation) + (let [hex (:: nat.hex encode byte) + hex (case (text.size hex) + 1 (format "0" hex) + _ hex)] + (format representation hex))) + "")) |