@@ -15,28 +15,29 @@ import securehash, md5, nimSHA2, strutils
15
15
type
16
16
Sha1Digest = array [20 , uint8 ]
17
17
18
- proc hash_sha1(s: string ): SecureHash {.procvar.} =
18
+ proc hash_sha1* (s: string ): SecureHash {.procvar.} =
19
19
secureHash(s)
20
20
21
- proc hash_sha256(s: string ): SHA256Digest {.procvar.} =
21
+ proc hash_sha256* (s: string ): SHA256Digest {.procvar.} =
22
22
computeSHA256(s)
23
23
24
- proc hash_md5 (s: string ): MD5Digest {.procvar.} =
25
- toMD5 (s)
24
+ proc hash_sha512 * (s: string ): SHA512Digest {.procvar.} =
25
+ computeSHA512 (s)
26
26
27
+ proc hash_md5* (s: string ): MD5Digest {.procvar.} =
28
+ toMD5(s)
29
+
27
30
iterator items(s: SecureHash): uint8 =
28
31
for n in Sha1Digest(s):
29
32
yield n
30
33
31
- proc `%` * [T: SecureHash | SHA256Digest | MD5Diges t ](x: T): string =
34
+ proc `%` * [T](x: T): string =
32
35
when x is SecureHash:
33
36
toLower($ x)
34
- elif x is SHA256Digest:
35
- toLower(nimSHA2.toHex(x))
36
37
elif x is MD5Digest:
37
38
$ x
38
39
else :
39
- discard
40
+ toLower(nimSHA2.toHex(x))
40
41
41
42
template hmac_x[T](key, data: string , hash: proc(s: string ): T, digest_size: int , block_size = 64, opad = 0x5c, ipad = 0x36): stmt =
42
43
var keyA: seq [uint8 ] = @[]
@@ -66,7 +67,10 @@ proc hmac_sha1*(key, data: string, block_size = 64, opad = 0x5c, ipad = 0x36): S
66
67
hmac_x(key, data, hash_sha1, 20, block_size, opad, ipad)
67
68
68
69
proc hmac_sha256*(key, data: string , block_size = 64, opad = 0x5c, ipad = 0x36): SHA256Digest =
69
- hmac_x(key, data, hash_sha256, 32, block_size, opad, ipad)
70
+ hmac_x(key, data, hash_sha256, 32, block_size, opad, ipad)
71
+
72
+ proc hmac_sha512*(key, data: string , block_size = 64, opad = 0x5c, ipad = 0x36): SHA512Digest =
73
+ hmac_x(key, data, hash_sha512, 32, block_size, opad, ipad)
70
74
71
75
proc hmac_md5*(key, data: string ): MD5Digest =
72
76
hmac_x(key, data, hash_md5, 16)
0 commit comments