<s> import hashlib <EOL> import hmac <EOL> import sys <EOL> if sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:2> : <EOL> text_type = unicode <EOL> else : <EOL> text_type = str <EOL> class Crypto : <EOL> @ staticmethod <EOL> def sha1_hmac_hash ( secret_key , content ) : <EOL> if isinstance ( secret_key , text_type ) : <EOL> secret_key = secret_key . encode ( '<STR_LIT:ascii>' ) <EOL> if isinstance ( content , text_type ) : <EOL> content = content . encode ( '<STR_LIT:ascii>' ) <EOL> return hmac . new ( hashlib . sha1 ( secret_key ) . digest ( ) , content , hashlib . sha1 ) . hexdigest ( ) <EOL> @ staticmethod <EOL> def sha256_hmac_hash ( secret_key , content ) : <EOL> if isinstance ( secret_key , text_type ) : <EOL> secret_key = secret_key . encode ( '<STR_LIT:ascii>' ) <EOL> if isinstance ( content , text_type ) : <EOL> content = content . encode ( '<STR_LIT:ascii>' ) <EOL> return hmac . new ( hashlib . sha256 ( secret_key ) . digest ( ) , content , hashlib . sha256 ) . hexdigest ( ) <EOL> @ staticmethod <EOL> def secure_compare ( left , right ) : <EOL> if left is None or right is None : <EOL> return False <EOL> left_bytes = [ ord ( char ) for char in left ] <EOL> right_bytes = [ ord ( char ) for char in right ] <EOL> if len ( left_bytes ) != len ( right_bytes ) : <EOL> return False <EOL> result = <NUM_LIT:0> <EOL> for left_byte , right_byte in zip ( left_bytes , right_bytes ) : <EOL> result |= left_byte ^ right_byte <EOL> return result == <NUM_LIT:0> </s>
