aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/hash.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/program/aedifex/hash.lux')
-rw-r--r--stdlib/source/program/aedifex/hash.lux27
1 files changed, 27 insertions, 0 deletions
diff --git a/stdlib/source/program/aedifex/hash.lux b/stdlib/source/program/aedifex/hash.lux
new file mode 100644
index 000000000..bd4396006
--- /dev/null
+++ b/stdlib/source/program/aedifex/hash.lux
@@ -0,0 +1,27 @@
+(.module:
+ [lux #*
+ ["." host (#+ import:)]
+ [data
+ ["." binary (#+ Binary)]]])
+
+## TODO: Replace with pure-Lux implementations of these algorithms
+## https://en.wikipedia.org/wiki/SHA-1#SHA-1_pseudocode
+## https://en.wikipedia.org/wiki/MD5#Algorithm
+(import: #long java/lang/String)
+
+(import: #long java/security/MessageDigest
+ (#static getInstance [java/lang/String] java/security/MessageDigest)
+ (digest [[byte]] [byte]))
+
+(type: #export Hash
+ Binary)
+
+(template [<name> <algorithm>]
+ [(def: #export (<name> value)
+ (-> Binary Hash)
+ (|> (java/security/MessageDigest::getInstance [<algorithm>])
+ (java/security/MessageDigest::digest [value])))]
+
+ [sha1 "SHA-1"]
+ [md5 "MD5"]
+ )