def test_urandom(): # argument n is a random int rand = _random.Random() n = rand.getrandbits(16) str = nt.urandom(n) result = len(str) AreEqual(isinstance(str, type("string")), True) AreEqual(n, result)
def test_urandom(self): # argument n is a random int rand = random.Random() n = rand.getrandbits(16) str = nt.urandom(n) result = len(str) self.assertTrue(isinstance(str, bytes)) self.assertEqual(n,result)
def test_urandom(): # argument n is a random int rand = _random.Random() n = rand.getrandbits(16) str = nt.urandom(n) result = len(str) AreEqual(isinstance(str,type("string")),True) AreEqual(n,result)
def encrypt(self, raw): iv = bytearray(os.urandom(16)) cipher = aes.AES(mode='cbc', key=self.key, iv=iv) # for when raw is an bytes object and not an str object. if isinstance(raw, str): data = bytearray(raw.encode('ascii')) else: data = bytearray(raw) while (len(data) / 16) % 1 != 0: data.append(0x00) cipher.encrypt(data) return bytes(iv + data)