def constantStrEqual(str1, str2):
    '''Do a constant-time comparison of str1 and str2, returning **True**
    if they are equal, **False** otherwise.

    :param str str1: first string to compare
    :param str str2: second string to compare
    :returns: **bool** **True** if str1 == str2, **False** otherwise
    '''
    try:
        from hmac import compare_digest
        return compare_digest(str1, str2)
    except __HOLE__:
        pass

    if len(str1) != len(str2):
        # we've already failed at this point, but loop anyway
        res = 1
        comp1 = bytearray(str2)
        comp2 = bytearray(str2)
    else:
        res = 0
        comp1 = bytearray(str1)
        comp2 = bytearray(str2)
    
    for a, b in izip(comp1, comp2):
        res |= a ^ b

    return res == 0
dataset/ETHPy150Open nskinkel/oppy/oppy/crypto/util.py/constantStrEqual