示例#1
0
    def test_randombytes_uniform(self):
        self.assertIsInstance(libnacl.randombytes_uniform(200), int)

        freq = {libnacl.randombytes_uniform(256): 1 for _ in range(65536)}

        self.assertEqual(256, len(freq))
        self.assertTrue(all(freq.values()))
示例#2
0
    def test_randombytes_uniform(self):
        self.assertIsInstance(libnacl.randombytes_uniform(200), int)

        freq = {libnacl.randombytes_uniform(256): 1 for _ in range(65536)}

        self.assertEqual(256, len(freq))
        self.assertTrue(all(freq.values()))
示例#3
0
def randint(a, b):
    """
    Return a cryptographically secure random integer N such that
    ``a <= N <= b``.
    """
    n = libnacl.randombytes_uniform(b) + a
    assert a <= n <= b
    return n
def randint(a, b):
    """
    Return a cryptographically secure random integer N such that
    ``a <= N <= b``.
    """
    n = libnacl.randombytes_uniform(b) + a
    assert a <= n <= b
    return n
示例#5
0
    def randomStr(size):
        if not isinstance(size, int):
            raise PlenumTypeError('size', size, int)
        if not size > 0:
            raise PlenumValueError('size', size, '> 0')
        # Approach 1
        rv = randombytes(size // 2).hex()

        return rv if size % 2 == 0 else rv + hex(randombytes_uniform(15))[-1]
示例#6
0
    def randomStr(size):
        if not isinstance(size, int):
            raise PlenumTypeError('size', size, int)
        if not size > 0:
            raise PlenumValueError('size', size, '> 0')
        # Approach 1
        rv = randombytes(size // 2).hex()

        return rv if size % 2 == 0 else rv + hex(randombytes_uniform(15))[-1]
示例#7
0
def random_string(sz: int) -> str:
    assert (sz > 0), "Expected random string size cannot be less than 1"
    rv = libnacl.randombytes(sz // 2).hex()
    return rv if sz % 2 == 0 else rv + hex(libnacl.randombytes_uniform(15))[-1]
示例#8
0
    def randomStr(size):
        assert (size > 0), "Expected random string size cannot be less than 1"
        # Approach 1
        rv = randombytes(size // 2).hex()

        return rv if size % 2 == 0 else rv + hex(randombytes_uniform(15))[-1]
示例#9
0
 def random_string(self, sz: int) -> str:
     assert (sz > 0), "Expected random string size cannot be less than 1"
     rv = libnacl.randombytes(sz // 2).hex()
     return rv if sz % 2 == 0 else rv + hex(libnacl.randombytes_uniform(15))[-1]