diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2018-12-14 20:21:03 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2018-12-14 20:21:03 -0800 |
| commit | 4fe63f253f58f87ab986fea38902d95f2a5ea338 (patch) | |
| tree | 12094f1c69b8ab375eb17507c959c43f9295c6c2 /lib/file_hash.nom | |
| parent | 6abec65843f0f37f7fc6032ac5db0fff3db71815 (diff) | |
Auto-updated to version 5
Diffstat (limited to 'lib/file_hash.nom')
| -rw-r--r-- | lib/file_hash.nom | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/lib/file_hash.nom b/lib/file_hash.nom index 32c7209..dd3d520 100644 --- a/lib/file_hash.nom +++ b/lib/file_hash.nom @@ -1,4 +1,4 @@ -#!/usr/bin/env nomsu -V4.12.12.8 +#!/usr/bin/env nomsu -V5.12.12.8 # This file defines some actions for hashing files and looking up files by hash. @@ -7,47 +7,47 @@ use "lib/base64.nom" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -lua> "local \%use_sha1, \%hashlib = pcall(require, 'openssl.digest')" +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 "\ - ..Hash collision: + assume ((hash "hello world") != (hash "goodbye")) or barf " + Hash collision: (hash "hello world") = \(hash "hello world") (hash "goodbye") = \(hash "goodbye")" assume (..) (..) - hash "\ - ..This is a really long string meant to stress test the hashing function and + 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" - assume ((hash "\000") != (hash "\000\000\000\000\000")) or barf "\ - ..Incorrect hashing of null strings" + assume ((hash "\000") != (hash "\000\000\000\000\000")) or barf \ + .."Incorrect hashing of null strings" - if %use_sha1: + if $use_sha1: assume ((hash "hello world") == "Kq5sNclPz7QV2+lfQIuc6R7oRu0=") -if %use_sha1: - externally (hash %) means: - %hash = (=lua "\%hashlib.new('sha1'):final(\%)") - return (base64 %hash) +if $use_sha1: + externally (hash $) means: + $hash = (=lua "\$hashlib.new('sha1'):final(\$)") + 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" - externally (hash %) means: - %bytes = (%::bytes) - %hash = (%bytes.1 << 7) - for %i in 2 to (size of %bytes): - %hash = ((1000003 * %hash) ~ %bytes.%i) - %hash = (%hash ~ (size of %bytes)) - return "\%hash" + externally (hash $) means: + $bytes = ($|bytes) + $hash = ($bytes.1 << 7) + for $i in 2 to (size of $bytes): + $hash = ((1000003 * $hash) ~ $bytes.$i) + $hash = ($hash ~ (size of $bytes)) + return "\$hash" -externally (file with hash %hash) means: - for %filename in (files for "."): - %contents = (read file %filename) - %file_hash = (hash %contents) - if (%file_hash == %hash): - return %filename +externally (file with hash $hash) means: + for $filename in (files for "."): + $contents = (read file $filename) + $file_hash = (hash $contents) + if ($file_hash == $hash): + return $filename -(hash of file %filename) parses as (hash (read file %filename)) +(hash of file $filename) parses as (hash (read file $filename)) |
