Exemplo n.º 1
0
 def test_backend(self):
     scrypt_mod.backend = None
     scrypt_mod._scrypt = None
     self.assertRaises(TypeError, scrypt_mod.scrypt, 's', 's', 2, 2, 2, 16)
     scrypt_mod._set_backend(self.backend)
     self.assertEqual(scrypt_mod.backend, self.backend)
     scrypt_mod.scrypt('s', 's', 2, 2, 2, 16)
     self.assertRaises(ValueError, scrypt_mod._set_backend, 'xxx')
     self.assertEqual(scrypt_mod.backend, self.backend)
     return
Exemplo n.º 2
0
    def test_other_backends(self):
        if self._already_tested_others:
            raise self.skipTest('already run under %r backend test' %
                                self._already_tested_others)
        self._already_tested_others = self.backend
        rng = self.getRandom()
        orig = scrypt_mod.backend
        available = set(name for name in scrypt_mod.backend_values
                        if scrypt_mod._has_backend(name))
        scrypt_mod._set_backend(orig)
        available.discard(self.backend)
        if not available:
            raise self.skipTest('no other backends found')
        warnings.filterwarnings('ignore',
                                '(?i)using builtin scrypt backend',
                                category=exc.PasslibSecurityWarning)
        for _ in range(10):
            secret = getrandbytes(rng, rng.randint(0, 64))
            salt = getrandbytes(rng, rng.randint(0, 64))
            n = 1 << rng.randint(1, 10)
            r = rng.randint(1, 8)
            p = rng.randint(1, 3)
            ks = rng.randint(1, 64)
            previous = None
            backends = set()
            for name in available:
                scrypt_mod._set_backend(name)
                self.assertNotIn(scrypt_mod._scrypt, backends)
                backends.add(scrypt_mod._scrypt)
                result = hexstr(scrypt_mod.scrypt(secret, salt, n, r, p, ks))
                self.assertEqual(len(result), 2 * ks)
                if previous is not None:
                    self.assertEqual(
                        result,
                        previous,
                        msg='%r output differs from others %r: %r' %
                        (name, available, [secret, salt, n, r, p, ks]))

        return
Exemplo n.º 3
0
 def test_default_backend(self):
     scrypt_mod._set_backend('default')
     self.assertEqual(scrypt_mod.backend, 'scrypt')
Exemplo n.º 4
0
 def setUp(self):
     scrypt_mod._set_backend(self.backend)
     super(_CommonScryptTest, self).setUp()
Exemplo n.º 5
0
 def set_backend(cls, name='any', dryrun=False):
     _scrypt._set_backend(name, dryrun=dryrun)