コード例 #1
0
 def __hash__(self):
     if self.__hashed is None:
         primary = getattr(
             self,
             self.__table__.primary_key.columns.values()[0].name)
         self.__hashed = id(self) if primary is None else hash(primary)
     return self.__hashed
コード例 #2
0
    def test_93_derive_digest(self):
        """test scram.derive_digest()"""
        # NOTE: this just does a light test, since derive_digest
        # is used by hash / verify, and is tested pretty well via those.
        hash = self.handler.derive_digest

        # check various encodings of password work.
        s1 = b"\x01\x02\x03"
        d1 = b"\xb2\xfb\xab\x82[tNuPnI\x8aZZ\x19\x87\xcen\xe9\xd3"
        self.assertEqual(hash(u("\u2168"), s1, 1000, "sha-1"), d1)
        self.assertEqual(hash(b"\xe2\x85\xa8", s1, 1000, "SHA-1"), d1)
        self.assertEqual(hash(u("IX"), s1, 1000, "sha1"), d1)
        self.assertEqual(hash(b"IX", s1, 1000, "SHA1"), d1)

        # check algs
        self.assertEqual(
            hash("IX", s1, 1000, "md5"),
            b"3\x19\x18\xc0\x1c/\xa8\xbf\xe4\xa3\xc2\x8eM\xe8od",
        )
        self.assertRaises(ValueError, hash, "IX", s1, 1000, "sha-666")

        # check rounds
        self.assertRaises(ValueError, hash, "IX", s1, 0, "sha-1")

        # unicode salts accepted as of passlib 1.7 (previous caused TypeError)
        self.assertEqual(hash(u("IX"), s1.decode("latin-1"), 1000, "sha1"), d1)
コード例 #3
0
    def test_93_derive_digest(self):
        """test scram.derive_digest()"""
        # NOTE: this just does a light test, since derive_digest
        # is used by hash / verify, and is tested pretty well via those.
        hash = self.handler.derive_digest

        # check various encodings of password work.
        s1 = b'\x01\x02\x03'
        d1 = b'\xb2\xfb\xab\x82[tNuPnI\x8aZZ\x19\x87\xcen\xe9\xd3'
        self.assertEqual(hash(u("\u2168"), s1, 1000, 'sha-1'), d1)
        self.assertEqual(hash(b"\xe2\x85\xa8", s1, 1000, 'SHA-1'), d1)
        self.assertEqual(hash(u("IX"), s1, 1000, 'sha1'), d1)
        self.assertEqual(hash(b"IX", s1, 1000, 'SHA1'), d1)

        # check algs
        self.assertEqual(hash("IX", s1, 1000, 'md5'),
                         b'3\x19\x18\xc0\x1c/\xa8\xbf\xe4\xa3\xc2\x8eM\xe8od')
        self.assertRaises(ValueError, hash, "IX", s1, 1000, 'sha-666')

        # check rounds
        self.assertRaises(ValueError, hash, "IX", s1, 0, 'sha-1')

        # unicode salts accepted as of passlib 1.7 (previous caused TypeError)
        self.assertEqual(hash(u("IX"), s1.decode("latin-1"), 1000, 'sha1'), d1)