# Test to make sure copy works. import unittest from Strobe.Strobe import Strobe from Strobe.Strobe import AuthenticationFailed class TestCopy(unittest.TestCase): def test_copy(self): a = Strobe(b'foo') b = Strobe(b'foo') msg = a.send_enc(b'atest') self.assertEqual(b'atest', b.recv_enc(msg)) c = b.copy() msg = a.send_enc(b'anothertest') # that both the original and copy work self.assertEqual(b'anothertest', b.recv_enc(msg)) self.assertEqual(b'anothertest', c.recv_enc(msg)) def test_set_state_from(self): a = Strobe(b'foo') b = Strobe(b'foo') c = b.copy() mac = a.send_mac(8) # That the wrong mac fails with self.assertRaises(AuthenticationFailed): b.recv_mac(b'random') # but the state can be reset b.set_state_from(c) # and then works fine b.recv_mac(mac)