def test_onetimeauth(self): msg = b'Hello, world!' key = nacl.randombytes(nacl.lookup('onetimeauth_KEYBYTES')) auth = nacl.onetimeauth(msg, key) self.assertIsInstance(auth, bytes) self.assertTrue(nacl.onetimeauth_verify(auth, msg, key)) self.assertEqual(len(auth), nacl.lookup('onetimeauth_BYTES')) msg = bytearray(msg) key = bytearray(key) auth = bytearray(auth) msg[0] ^= 0xff; self.assertFalse(nacl.onetimeauth_verify(auth, msg, key)) msg[0] ^= 0xff; self.assertTrue(nacl.onetimeauth_verify(auth, msg, key)) key[0] ^= 0xff; self.assertFalse(nacl.onetimeauth_verify(auth, msg, key)) key[0] ^= 0xff; self.assertTrue(nacl.onetimeauth_verify(auth, msg, key)) auth[0] ^= 0xff; self.assertFalse(nacl.onetimeauth_verify(auth, msg, key)) auth[0] ^= 0xff; self.assertTrue(nacl.onetimeauth_verify(auth, msg, key))
def test_hash(self): msg = b'Foo bar baz' h = nacl.hash(msg) self.assertIsInstance(h, bytes) self.assertEqual(len(h), nacl.lookup('hash_BYTES'))