def test_codec_identity(self): # Not zero-destructive self.assertEqual(codec.hex_decode(codec.hex_encode(ZERO_BYTES)), ZERO_BYTES) self.assertEqual(codec.hex_decode(codec.hex_encode(RANDOM_BYTES_1024)), RANDOM_BYTES_1024) self.assertEqual(codec.hex_decode(codec.hex_encode(RANDOM_BYTES_2048)), RANDOM_BYTES_2048) self.assertEqual( codec.hex_decode(codec.hex_encode(RANDOM_BYTES_4093)), RANDOM_BYTES_4093)
def test_codec_identity(self): # Not zero-destructive self.assertEqual(hex_decode(hex_encode(zero_bytes)), zero_bytes) self.assertEqual(hex_decode(hex_encode(random_bytes_1024)), random_bytes_1024) self.assertEqual(hex_decode(hex_encode(random_bytes_2048)), random_bytes_2048) self.assertEqual( hex_decode(hex_encode(random_bytes_len_4093)), random_bytes_len_4093)
def sha1_hex_digest(*inputs): """ Calculates hexadecimal representation of the SHA-1 digest of a variable number of inputs. :param inputs: A variable number of inputs for which the digest will be calculated. :returns: Hexadecimal representation of the SHA-1 digest. """ return codec.hex_encode(sha1_digest(*inputs))
def sha1_hex_digest(*inputs): """ Calculates hexadecimal representation of the SHA-1 digest of a variable number of inputs. :param inputs: A variable number of inputs for which the digest will be calculated. :returns: Hexadecimal representation of the SHA-1 digest. """ return hex_encode(sha1_digest(*inputs))
def generate_random_hex_string(length=8, rand_func=generate_random_bytes): """ Generates a random ASCII-encoded hexadecimal string of an even length. :param length: Length of the string to be returned. Default 32. The length MUST be a positive even number. :param rand_func: Random bytes generator function. :returns: A string representation of a randomly-generated hexadecimal string. """ #if length % 2 or length <= 0: if length & 1 or length <= 0: raise ValueError("This function expects a positive even number " "length: got length `%r`." % length) return codec.hex_encode(rand_func(length >> 1))
def test_value(self): self.assertEqual(md5_hex_digest(*inputs), hex_encode(input_md5_digest))
def test_value(self): self.assertEqual(sha1_hex_digest(*inputs), hex_encode(input_sha1_digest))
def test_value(self): self.assertEqual(hash.md5_hex_digest(*INPUTS), codec.hex_encode(INPUT_MD5_DIGEST))
def test_value(self): self.assertEqual(hash.sha1_hex_digest(*INPUTS), codec.hex_encode(INPUT_SHA1_DIGEST))