Skip to content
This repository was archived by the owner on May 9, 2020. It is now read-only.

Commit 6157360

Browse files
kamilbednarzfpedrini
authored andcommitted
Use itertools for HMAC validation
1 parent 30621ed commit 6157360

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

chef/encrypted_data_bag_item.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import base64
99
import chef
1010
import hashlib
11+
import itertools
1112

1213
class EncryptedDataBagItem(DataBagItem):
1314
SUPPORTED_ENCRYPTION_VERSIONS = (1,2)
@@ -130,10 +131,8 @@ def _validate_hmac(self):
130131
expected_bytes = map(ord, expected_hmac)
131132
candidate_hmac_bytes = map(ord, self.hmac)
132133
valid = len(expected_bytes) ^ len(candidate_hmac_bytes)
133-
index = 0
134-
for value in expected_bytes:
135-
valid |= value ^ candidate_hmac_bytes[index]
136-
index += 1
134+
for expected_byte, candidate_byte in itertools.izip_longest(expected_bytes, candidate_hmac_bytes):
135+
valid |= expected_byte ^ candidate_byte
137136
return valid == 0
138137

139138
def decrypt(self):

0 commit comments

Comments
 (0)