Skip to content

Commit

Permalink
Npm package ready
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeByZach committed Jul 28, 2021
1 parent 9debb7b commit a881dbb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Common Usage
-------

```html
<script src="https://cdn.jsdelivr.net/gh/codebyzach/jhash.js@latest/jhash.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jhash.js@latest/jhash.min.js"></script>
<script>
var md5 = JHash.hex_md5("string");
var md5_hmac = JHash.hex_hmac_md5("key", "data");
Expand All @@ -34,6 +34,7 @@ Common Usage
</script>
```


Other Output Encodings
-------

Expand Down
10 changes: 5 additions & 5 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
short = {'ripemd160': 'rmd160'}
test_strings = ['hello', 'world', u'fred\u1234'.encode('utf-8'), 'this is a longer test message to confirm that multiple blocks are handled correctly by the hashing algorithm']

print ("""<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/></head><body><script src="jhash.js"></script>""")
print ("""<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/></head><body><script src="https://cdn.jsdelivr.net/npm/jhash.js@latest/jhash.min.js"></script>""")

for alg in all_algs:
algs = short.get(alg, alg)
Expand All @@ -31,11 +31,11 @@
for t in test_strings:
h = hashlib.new(alg)
h.update(t)
print ("check(Hash.hex_%s('%s'), '%s');" % (algs, t, h.hexdigest()))
print ("check(Hash.b64_%s('%s'), '%s');" % (algs, t, base64.b64encode(h.digest()).rstrip('=')))
print ("check(JHash.hex_%s('%s'), '%s');" % (algs, t, h.hexdigest()))
print ("check(JHash.b64_%s('%s'), '%s');" % (algs, t, base64.b64encode(h.digest()).rstrip('=')))
h = hmac.new('key', t, lambda: hashlib.new(alg))
print ("check(Hash.hex_hmac_%s('key', '%s'), '%s');" % (algs, t, h.hexdigest()))
print ("check(Hash.b64_hmac_%s('key', '%s'), '%s');" % (algs, t, base64.b64encode(h.digest()).rstrip('=')))
print ("check(JHash.hex_hmac_%s('key', '%s'), '%s');" % (algs, t, h.hexdigest()))
print ("check(JHash.b64_hmac_%s('key', '%s'), '%s');" % (algs, t, base64.b64encode(h.digest()).rstrip('=')))

print ("""
document.write('Tests competed - ' + pass + ' passed; ' + fail + ' failed.<br/><br/>');
Expand Down

0 comments on commit a881dbb

Please sign in to comment.