Пример #1
0
 def test_codec_identity(self):
   self.assertEqual(
     codec.decimal_decode(codec.decimal_encode(ZERO_BYTES)),
     ZERO_BYTES)
   self.assertEqual(
     codec.decimal_decode(codec.decimal_encode(RANDOM_BYTES_1024)),
     RANDOM_BYTES_1024)
   self.assertEqual(
     codec.decimal_decode(codec.decimal_encode(RANDOM_BYTES_2048)),
     RANDOM_BYTES_2048)
   self.assertEqual(
     codec.decimal_decode(codec.decimal_encode(RANDOM_BYTES_4093)),
     RANDOM_BYTES_4093)
Пример #2
0
 def test_codec_identity(self):
   self.assertEqual(
     decimal_decode(decimal_encode(zero_bytes)),
     zero_bytes)
   self.assertEqual(
     decimal_decode(decimal_encode(random_bytes_1024)),
     random_bytes_1024)
   self.assertEqual(
     decimal_decode(decimal_encode(random_bytes_2048)),
     random_bytes_2048)
   self.assertEqual(
     decimal_decode(decimal_encode(random_bytes_len_4093)),
     random_bytes_len_4093)
Пример #3
0
def generate_nonce(n_bits=64):
    """
    Generates a random ASCII-encoded unsigned integral number in decimal
    representation.

    The nonce/timestamp pair should always be unique to prevent replay attacks.

    :see: Nonce and Timestamp (http://tools.ietf.org/html/rfc5849#section-3.3)
    :param n_bits:
        Bit size. Default 64.
    :returns:
        A string representation of a randomly-generated ASCII-encoded
        decimal-representation unsigned integral number based on the bit size
        specified.
    """
    return decimal_encode(generate_random_bits(n_bits))