Skip to content

Commit df22181

Browse files
committed
Python: Add tests of hmac
1 parent d55e9d5 commit df22181

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import hmac
2+
import hashlib
3+
4+
key = b"<secret key>"
5+
6+
hmac_obj = hmac.new(key, b"secret message", "sha256") # $ MISSING: CryptographicOperation CryptographicOperationInput=b"secret message" CryptographicOperationAlgorithm=SHA256
7+
print(hmac_obj.digest())
8+
print(hmac_obj.hexdigest())
9+
10+
hmac_obj = hmac.new(key, msg=b"secret message", digestmod="sha256") # $ MISSING: CryptographicOperation CryptographicOperationInput=b"secret message" CryptographicOperationAlgorithm=SHA256
11+
print(hmac_obj.hexdigest())
12+
13+
14+
hmac_obj = hmac.new(key, digestmod="sha256")
15+
hmac_obj.update(b"secret") # $ MISSING: CryptographicOperation CryptographicOperationInput=b"secret" CryptographicOperationAlgorithm=SHA256
16+
hmac_obj.update(msg=b" message") # $ MISSING: CryptographicOperation CryptographicOperationInput=b" message" CryptographicOperationAlgorithm=SHA256
17+
print(hmac_obj.hexdigest())
18+
19+
20+
hmac_obj = hmac.new(key, b"secret message", hashlib.sha256) # $ MISSING: CryptographicOperation CryptographicOperationInput=b"secret message" CryptographicOperationAlgorithm=SHA256
21+
print(hmac_obj.hexdigest())
22+
23+
24+
# like hmac.new
25+
hmac_obj = hmac.HMAC(key, digestmod="sha256")
26+
hmac_obj.update(b"secret message") # $ MISSING: CryptographicOperation CryptographicOperationInput=b"secret message" CryptographicOperationAlgorithm=SHA256
27+
print(hmac_obj.hexdigest())
28+
29+
30+
dig = hmac.digest(key, b"secret message", "sha256") # $ MISSING: CryptographicOperation CryptographicOperationInput=b"secret message" CryptographicOperationAlgorithm=SHA256
31+
print(dig)
32+
dig = hmac.digest(key, msg=b"secret message", digest="sha256") # $ MISSING: CryptographicOperation CryptographicOperationInput=b"secret message" CryptographicOperationAlgorithm=SHA256
33+
print(dig)

0 commit comments

Comments
 (0)