Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

40 lines
817 B

  1. # Test to make sure copy works.
  2. import unittest
  3. from Strobe.Strobe import Strobe
  4. from Strobe.Strobe import AuthenticationFailed
  5. class TestCopy(unittest.TestCase):
  6. def test_copy(self):
  7. a = Strobe(b'foo')
  8. b = Strobe(b'foo')
  9. msg = a.send_enc(b'atest')
  10. self.assertEqual(b'atest', b.recv_enc(msg))
  11. c = b.copy()
  12. msg = a.send_enc(b'anothertest')
  13. # that both the original and copy work
  14. self.assertEqual(b'anothertest', b.recv_enc(msg))
  15. self.assertEqual(b'anothertest', c.recv_enc(msg))
  16. def test_set_state_from(self):
  17. a = Strobe(b'foo')
  18. b = Strobe(b'foo')
  19. c = b.copy()
  20. mac = a.send_mac(8)
  21. # That the wrong mac fails
  22. with self.assertRaises(AuthenticationFailed):
  23. b.recv_mac(b'random')
  24. # but the state can be reset
  25. b.set_state_from(c)
  26. # and then works fine
  27. b.recv_mac(mac)