Skip to content

Commit ada96d4

Browse files
committed
replaced % operator w/ toHex proc, closes #1
1 parent c9a84ea commit ada96d4

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

hmac.nim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ iterator items(s: SecureHash): uint8 =
3131
for n in Sha1Digest(s):
3232
yield n
3333

34-
proc `%`*[T](x: T): string =
34+
proc toHex*[T](x: T): string {.inline.} =
3535
when x is SecureHash:
3636
toLower($x)
3737
elif x is MD5Digest:
@@ -78,27 +78,27 @@ proc hmac_md5*(key, data: string): MD5Digest =
7878
7979
when isMainModule:
8080
81-
var result = %hmac_sha1("key", "The quick brown fox jumps over the lazy dog")
81+
var result = toHex(hmac_sha1("key", "The quick brown fox jumps over the lazy dog"))
8282
echo result
8383
assert(result == "de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9","Incorrect hash")
8484
8585
let longKey = "oiJkCotyEAcqEtbHAxwR0sj7Fl4CAT2xdT2oYJep6Wzes2umipBUzocVSwp7nL5ns4xDrPIBEBHKwIr3LlQLZmCw1wStOMSke9SDvQ2Gayj5ZGzvZ1T1uVyN4DcGenYd"
86-
result = %hmac_sha1(longKey, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras ut nibh sit amet felis volutpat pellentesque eu at tellus. Etiam posuere justo eget mi porta porta.")
86+
result = toHex(hmac_sha1(longKey, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras ut nibh sit amet felis volutpat pellentesque eu at tellus. Etiam posuere justo eget mi porta porta."))
8787
echo result
8888
assert(result == "a0d87be75bb531af746ab7988e1e8058e7bc17f0","Incorrect hash")
8989
90-
result = %hmac_sha256("ubuntu", "Canonical to offer 5 years of support, but Snap packages mean latest features factor in.")
90+
result = toHex(hmac_sha256("ubuntu", "Canonical to offer 5 years of support, but Snap packages mean latest features factor in."))
9191
echo result
9292
assert(result == "f53abed8001d0b7c8a64edc011854bded49e1ed55e5d5f5455b7b2ecf6506884", "Incorrect hash")
9393
94-
result = %hmac_sha256(longKey, "Nim (formerly known as \"Nimrod\") is a statically typed, imperative programming language that tries to give the programmer ultimate power without compromises on runtime efficiency. This means it focuses on compile-time mechanisms in all their various forms.")
94+
result = toHex(hmac_sha256(longKey, "Nim (formerly known as \"Nimrod\") is a statically typed, imperative programming language that tries to give the programmer ultimate power without compromises on runtime efficiency. This means it focuses on compile-time mechanisms in all their various forms."))
9595
echo result
9696
assert(result == "8df227ae87aee5cad77c395eb4a589469421f4d23ced1a8e93270cd4c4fd9cbf", "Incorrect hash")
9797
98-
result = %hmac_md5("Jefe", "what do ya want for nothing?")
98+
result = toHex(hmac_md5("Jefe", "what do ya want for nothing?"))
9999
echo result
100100
assert(result == "750c783e6ab0b503eaa86e310a5db738","Incorrect hash")
101101
102-
result = %hmac_md5(longKey, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras ut nibh sit amet felis volutpat pellentesque eu at tellus. Etiam posuere justo eget mi porta porta.")
102+
result = toHex(hmac_md5(longKey, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras ut nibh sit amet felis volutpat pellentesque eu at tellus. Etiam posuere justo eget mi porta porta."))
103103
echo result
104104
assert(result == "35acf8ac84d15ed02a4cd94331fc0aaa","Incorrect hash")

hmac.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = "0.1.3"
1+
version = "0.1.4"
22
author = "Huy Doan"
33
description = "HMAC hashing in Nim"
44
license = "MIT"

0 commit comments

Comments
 (0)