Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
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))
Esempio n. 4
0
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))
Esempio n. 5
0
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))
Esempio n. 6
0
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))
Esempio n. 7
0
 def test_value(self):
   self.assertEqual(md5_hex_digest(*inputs), hex_encode(input_md5_digest))
Esempio n. 8
0
 def test_value(self):
   self.assertEqual(sha1_hex_digest(*inputs), hex_encode(input_sha1_digest))
Esempio n. 9
0
 def test_value(self):
     self.assertEqual(hash.md5_hex_digest(*INPUTS),
                      codec.hex_encode(INPUT_MD5_DIGEST))
Esempio n. 10
0
 def test_value(self):
     self.assertEqual(hash.sha1_hex_digest(*INPUTS),
                      codec.hex_encode(INPUT_SHA1_DIGEST))