remove random shuffle function for systemrandom equivalent
This commit is contained in:
parent
fb85856f76
commit
5dddeb3f10
8 changed files with 28 additions and 40 deletions
|
@ -14,7 +14,7 @@ from onionrutils import stringvalidators, mnemonickeys
|
|||
import onionrcrypto as crypto, onionrexceptions
|
||||
|
||||
class OnionrCryptoTests(unittest.TestCase):
|
||||
|
||||
|
||||
def test_blake2b(self):
|
||||
self.assertEqual(crypto.hashers.blake2b_hash('test'), crypto.hashers.blake2b_hash(b'test'))
|
||||
self.assertEqual(crypto.hashers.blake2b_hash(b'test'), crypto.hashers.blake2b_hash(b'test'))
|
||||
|
@ -26,9 +26,9 @@ class OnionrCryptoTests(unittest.TestCase):
|
|||
pass
|
||||
else:
|
||||
self.assertTrue(False)
|
||||
|
||||
|
||||
self.assertEqual(nacl.hash.blake2b(b'test'), crypto.hashers.blake2b_hash(b'test'))
|
||||
|
||||
|
||||
def test_sha3256(self):
|
||||
hasher = hashlib.sha3_256()
|
||||
self.assertEqual(crypto.hashers.sha3_hash('test'), crypto.hashers.sha3_hash(b'test'))
|
||||
|
@ -41,18 +41,18 @@ class OnionrCryptoTests(unittest.TestCase):
|
|||
pass
|
||||
else:
|
||||
self.assertTrue(False)
|
||||
|
||||
|
||||
hasher.update(b'test')
|
||||
normal = hasher.hexdigest()
|
||||
self.assertEqual(crypto.hashers.sha3_hash(b'test'), normal)
|
||||
|
||||
|
||||
def valid_default_id(self):
|
||||
self.assertTrue(stringvalidators.validate_pub_key(crypto.pub_key))
|
||||
|
||||
|
||||
def test_human_readable_length(self):
|
||||
human = mnemonickeys.get_human_readable_ID()
|
||||
self.assertTrue(len(human.split('-')) == 16)
|
||||
|
||||
|
||||
def test_safe_compare(self):
|
||||
self.assertTrue(crypto.cryptoutils.safe_compare('test', 'test'))
|
||||
self.assertTrue(crypto.cryptoutils.safe_compare('test', b'test'))
|
||||
|
@ -63,13 +63,6 @@ class OnionrCryptoTests(unittest.TestCase):
|
|||
pass
|
||||
else:
|
||||
self.assertTrue(False)
|
||||
|
||||
def test_random_shuffle(self):
|
||||
# Small chance that the randomized list will be same. Rerun test a couple times if it fails
|
||||
startList = ['cat', 'dog', 'moose', 'rabbit', 'monkey', 'crab', 'human', 'dolphin', 'whale', 'etc'] * 10
|
||||
|
||||
self.assertNotEqual(startList, list(crypto.cryptoutils.random_shuffle(startList)))
|
||||
self.assertTrue(len(list(crypto.cryptoutils.random_shuffle(startList))) == len(startList))
|
||||
|
||||
def test_asymmetric(self):
|
||||
keyPair = crypto.generate()
|
||||
|
@ -87,12 +80,12 @@ class OnionrCryptoTests(unittest.TestCase):
|
|||
pass
|
||||
else:
|
||||
self.assertTrue(False)
|
||||
|
||||
|
||||
blankMessage = crypto.encryption.pub_key_encrypt('', keyPair2[0])
|
||||
self.assertTrue('' == crypto.encryption.pub_key_decrypt(blankMessage, privkey=keyPair2[1], encodedData=False).decode())
|
||||
# Try to encrypt arbitrary bytes
|
||||
crypto.encryption.pub_key_encrypt(os.urandom(32), keyPair2[0])
|
||||
|
||||
|
||||
def test_pub_from_priv(self):
|
||||
priv = nacl.signing.SigningKey.generate().encode(encoder=nacl.encoding.Base32Encoder)
|
||||
pub = crypto.cryptoutils.getpubfrompriv.get_pub_key_from_priv(priv)
|
||||
|
@ -114,9 +107,9 @@ class OnionrCryptoTests(unittest.TestCase):
|
|||
pass
|
||||
else:
|
||||
self.assertFalse(True)
|
||||
|
||||
|
||||
gen = crypto.generate_deterministic('weakpassword', bypassCheck=True)
|
||||
|
||||
|
||||
password = base64.b64encode(os.urandom(32))
|
||||
gen1 = crypto.generate_deterministic(password)
|
||||
gen2 = crypto.generate_deterministic(password)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue