由于
python的一些版本问题,我必然会使用自定义函数来比较HMAC(SHA512).为此我发现了这个功能:
def compare_digest(x, y):
if not (isinstance(x, bytes) and isinstance(y, bytes)):
logfile.debug("both inputs should be instances of bytes")
if len(x) != len(y):
return False
result = 0
for a, b in zip(x, y):
result |= a ^ b
return result == 0
我在Django中使用它,因此我创建了一个记录器(logfile),它将调试消息保存到文件中.
代码在此步骤中断:
result |= a ^ b
但是,我不知道| =运算符代表什么,这里发生了什么.如果有人可以解释这个我可以尝试重写这个.
我的python版本(不幸的是2.7.4)与2.7.7我不会有问题,因为该函数将被正确移植并可用.