def test_binaryLongConvert(self): MAX = sys.maxsize with warnings.catch_warnings(): warnings.simplefilter('ignore', category=DeprecationWarning) for iteration in range(500): n = 0 for i in range(10): n += random.randrange(MAX) s = cryptutil.longToBinary(n) assert isinstance(s, six.binary_type) n_prime = cryptutil.binaryToLong(s) assert n == n_prime, (n, n_prime) cases = [(b'\x00', 0), (b'\x01', 1), (b'\x7F', 127), (b'\x00\xFF', 255), (b'\x00\x80', 128), (b'\x00\x81', 129), (b'\x00\x80\x00', 32768), (b'OpenID is cool', 1611215304203901150134421257416556)] with warnings.catch_warnings(): warnings.simplefilter('ignore', category=DeprecationWarning) for s, n in cases: n_prime = cryptutil.binaryToLong(s) s_prime = cryptutil.longToBinary(n) assert n == n_prime, (s, n, n_prime) assert s == s_prime, (n, s, s_prime)
def test_binaryLongConvert(): MAX = sys.maxint for iteration in xrange(500): n = 0L for i in range(10): n += long(random.randrange(MAX)) s = cryptutil.longToBinary(n) assert type(s) is str n_prime = cryptutil.binaryToLong(s) assert n == n_prime, (n, n_prime) cases = [ ('\x00', 0L), ('\x01', 1L), ('\x00\xFF', 255L), ('\x00\x80', 128L), ('\x00\x81', 129L), ('\x00\x80\x00', 32768L), ('OpenID is cool', 1611215304203901150134421257416556L) ] for s, n in cases: n_prime = cryptutil.binaryToLong(s) s_prime = cryptutil.longToBinary(n) assert n == n_prime, (s, n, n_prime) assert s == s_prime, (n, s, s_prime)
def test_binaryLongConvert(): MAX = sys.maxsize for iteration in range(500): n = 0 for i in range(10): n += int(random.randrange(MAX)) s = cryptutil.longToBinary(n) assert isinstance(s, bytes) n_prime = cryptutil.binaryToLong(s) assert n == n_prime, (n, n_prime) cases = [ (b'\x00', 0), (b'\x01', 1), (b'\x7F', 127), (b'\x00\xFF', 255), (b'\x00\x80', 128), (b'\x00\x81', 129), (b'\x00\x80\x00', 32768), (b'OpenID is cool', 1611215304203901150134421257416556) ] for s, n in cases: n_prime = cryptutil.binaryToLong(s) s_prime = cryptutil.longToBinary(n) assert n == n_prime, (s, n, n_prime) assert s == s_prime, (n, s, s_prime)
def test_binaryLongConvert(): MAX = sys.maxint for iteration in xrange(500): n = 0L for i in range(10): n += long(random.randrange(MAX)) s = cryptutil.longToBinary(n) assert type(s) is str n_prime = cryptutil.binaryToLong(s) assert n == n_prime, (n, n_prime) cases = [('\x00', 0L), ('\x01', 1L), ('\x7F', 127L), ('\x00\xFF', 255L), ('\x00\x80', 128L), ('\x00\x81', 129L), ('\x00\x80\x00', 32768L), ('OpenID is cool', 1611215304203901150134421257416556L)] for s, n in cases: n_prime = cryptutil.binaryToLong(s) s_prime = cryptutil.longToBinary(n) assert n == n_prime, (s, n, n_prime) assert s == s_prime, (n, s, s_prime)
def xorSecret(self, composite, secret, hash_func): dh_shared = self.getSharedSecret(composite) hashed_dh_shared = hash_func(cryptutil.longToBinary(dh_shared)) return strxor(secret, hashed_dh_shared)
def xorSecret(self, composite, secret): dh_shared = self.getSharedSecret(composite) sha1_dh_shared = cryptutil.sha1(cryptutil.longToBinary(dh_shared)) return strxor(secret, sha1_dh_shared)