aboutsummaryrefslogtreecommitdiff
path: root/lib/file_hash.nom
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-12-30 19:04:34 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-12-30 19:04:45 -0800
commit8a3c32408733a2f5e14f8a2dbafa3f980b2f73a1 (patch)
tree68f1e8a8b956c33ed24cc7a6a369fd97b8849321 /lib/file_hash.nom
parent359152da1772ce501609edd8f84b4985ed3e42f2 (diff)
Update to new syntax.
Diffstat (limited to 'lib/file_hash.nom')
-rw-r--r--lib/file_hash.nom28
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/file_hash.nom b/lib/file_hash.nom
index dd3d520..a45b684 100644
--- a/lib/file_hash.nom
+++ b/lib/file_hash.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V5.12.12.8
+#!/usr/bin/env nomsu -V6.12.12.8
#
This file defines some actions for hashing files and looking up files by hash.
@@ -10,19 +10,21 @@ use "lib/base64.nom"
lua> "local \$use_sha1, \$hashlib = pcall(require, 'openssl.digest')"
test:
assume (hash "hello world") == (hash "hello world")
- assume ((hash "hello world") != (hash "goodbye")) or barf "
+ assume ((hash "hello world") != (hash "goodbye")) or barf ("
Hash collision:
(hash "hello world") = \(hash "hello world")
- (hash "goodbye") = \(hash "goodbye")"
+ (hash "goodbye") = \(hash "goodbye")
+ ")
- assume (..)
- (..)
- hash "
+ assume
+ (
+ hash ("
This is a really long string meant to stress test the hashing function and
- ensure that it's not overflowing with long inputs."
- ..!= "inf"
+ ensure that it's not overflowing with long inputs.
+ ")
+ ) != "inf"
- assume ((hash "\000") != (hash "\000\000\000\000\000")) or barf \
+ assume ((hash "\000") != (hash "\000\000\000\000\000")) or barf
.."Incorrect hashing of null strings"
if $use_sha1:
@@ -34,9 +36,13 @@ if $use_sha1:
return (base64 $hash)
..else:
# TODO: remove warning?
- say "\027[31;1mWARNING: OpenSSL module not found. Defaulting to a non-cryptographically secure hash function.\027[0m"
+ say ("
+ \027[31;1mWARNING: OpenSSL module not found. Defaulting to a non-cryptographically secure \
+ ..hash function.\027[0m
+ ")
+
externally (hash $) means:
- $bytes = ($|bytes)
+ $bytes = ($, bytes)
$hash = ($bytes.1 << 7)
for $i in 2 to (size of $bytes):
$hash = ((1000003 * $hash) ~ $bytes.$i)