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

Commit bc62035

Browse files
committed
Refactor HMAC validation
1 parent f3413df commit bc62035

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

chef/encrypted_data_bag_item.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,9 @@ def __init__(self, key, data, iv, hmac):
126126

127127
def _validate_hmac(self):
128128
expected_hmac = hmac.new(self.key, self.encoded_data, hashlib.sha256).digest()
129-
expected_bytes = map(ord, expected_hmac)
130-
candidate_hmac_bytes = map(ord, self.hmac)
131-
valid = len(expected_bytes) ^ len(candidate_hmac_bytes)
132-
for expected_byte, candidate_byte in itertools.izip_longest(expected_bytes, candidate_hmac_bytes):
133-
valid |= expected_byte ^ candidate_byte
129+
valid = len(expected_hmac) ^ len(self.hmac)
130+
for expected_char, candidate_char in itertools.izip_longest(expected_hmac, self.hmac):
131+
valid |= ord(expected_char) ^ ord(candidate_char)
134132
return valid == 0
135133

136134
def decrypt(self):

0 commit comments

Comments
 (0)