shithub: mc

Download patch

ref: 6b0f942d7b95740123e84dbd8aeab15f336a18c6
parent: 38585ffa91d7b6e7b9e4f688e3f9fa84a48f1925
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Jun 3 19:07:27 EDT 2014

Factor out hash printing code.

    All tests share it.

--- a/libcryptohash/test/md5-test.myr
+++ b/libcryptohash/test/md5-test.myr
@@ -1,22 +1,14 @@
 use std
 use cryptohash
 
+use "printhash.use"
+
 const main = {
-	print(cryptohash.md5(""))
-	print(cryptohash.md5("h"))
+	print(cryptohash.md5("")[:])
+	print(cryptohash.md5("h")[:])
 	/* 64 byte block */
-	print(cryptohash.md5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
+	print(cryptohash.md5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:])
 	/* tail spanning */
-	print(cryptohash.md5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb"))
+	print(cryptohash.md5("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:])
 }
 
-const print = {b
-	for x in b
-		if (x <= 0xf)
-			std.put("0%xb", x)
-		else
-			std.put("%xb", x)
-		;;
-	;;
-        std.put("\n")
-}
binary files /dev/null b/libcryptohash/test/printhash.use differ
--- a/libcryptohash/test/sha1-test.myr
+++ b/libcryptohash/test/sha1-test.myr
@@ -1,22 +1,14 @@
 use std
 use cryptohash
 
+use "printhash.use"
+
 const main = {
-	print(cryptohash.sha1(""))
-	print(cryptohash.sha1("h"))
+	print(cryptohash.sha1("")[:])
+	print(cryptohash.sha1("h")[:])
 	/* 64 byte block */
-	print(cryptohash.sha1("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
+	print(cryptohash.sha1("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:])
 	/* tail spanning */
-	print(cryptohash.sha1("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb"))
+	print(cryptohash.sha1("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:])
 }
 
-const print = {b
-	for x in b
-		if (x <= 0xf)
-			std.put("0%xb", x)
-		else
-			std.put("%xb", x)
-		;;
-	;;
-        std.put("\n")
-}
--- a/libcryptohash/test/sha224-test.myr
+++ b/libcryptohash/test/sha224-test.myr
@@ -1,22 +1,14 @@
 use std
 use cryptohash
 
+use "printhash.use"
+
 const main = {
-	print(cryptohash.sha224(""))
-	print(cryptohash.sha224("h"))
+	print(cryptohash.sha224("")[:])
+	print(cryptohash.sha224("h")[:])
 	/* 64 byte block */
-	print(cryptohash.sha224("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
+	print(cryptohash.sha224("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:])
 	/* tail spanning */
-	print(cryptohash.sha224("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb"))
+	print(cryptohash.sha224("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:])
 }
 
-const print = {b
-	for x in b
-		if (x <= 0xf)
-			std.put("0%xb", x)
-		else
-			std.put("%xb", x)
-		;;
-	;;
-        std.put("\n")
-}
--- a/libcryptohash/test/sha256-test.myr
+++ b/libcryptohash/test/sha256-test.myr
@@ -1,22 +1,14 @@
 use std
 use cryptohash
 
+use "printhash.use"
+
 const main = {
-	print(cryptohash.sha256(""))
-	print(cryptohash.sha256("h"))
+	print(cryptohash.sha256("")[:])
+	print(cryptohash.sha256("h")[:])
 	/* 64 byte block */
-	print(cryptohash.sha256("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
+	print(cryptohash.sha256("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:])
 	/* tail spanning */
-	print(cryptohash.sha256("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb"))
+	print(cryptohash.sha256("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:])
 }
 
-const print = {b
-	for x in b
-		if (x <= 0xf)
-			std.put("0%xb", x)
-		else
-			std.put("%xb", x)
-		;;
-	;;
-        std.put("\n")
-}
--- a/libcryptohash/test/sha512-test.myr
+++ b/libcryptohash/test/sha512-test.myr
@@ -1,22 +1,14 @@
 use std
 use cryptohash
 
+use "printhash.use"
+
 const main = {
-	print(cryptohash.sha512(""))
-	print(cryptohash.sha512("h"))
+	print(cryptohash.sha512("")[:])
+	print(cryptohash.sha512("h")[:])
 	/* 64 byte block */
-	print(cryptohash.sha512("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
+	print(cryptohash.sha512("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")[:])
 	/* tail spanning */
-	print(cryptohash.sha512("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb"))
+	print(cryptohash.sha512("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbb")[:])
 }
 
-const print = {b
-	for x in b
-		if (x <= 0xf)
-			std.put("0%xb", x)
-		else
-			std.put("%xb", x)
-		;;
-	;;
-        std.put("\n")
-}
--- a/libcryptohash/test/tests
+++ b/libcryptohash/test/tests
@@ -1,5 +1,6 @@
 FLAGS=-I../
 mkdir -p tmpout
+EXTRA_SRC=printhash.myr
 # Format:
 # [B|F] testname [E|P] result
 #    [B|F]: Compiler outcome.