test_encrypt.py 827 B

12345678910111213141516171819202122
  1. from panda3d import core
  2. import pytest
  3. @pytest.mark.skipif(not hasattr(core, 'encrypt_string'), reason="Requires OpenSSL")
  4. def test_encrypt_string():
  5. # Test encrypt and then decrypt cycle
  6. for algorithm in ('', 'bf-cbc', 'aes-256-cbc'):
  7. enc = core.encrypt_string('abcdefg', '12345', algorithm)
  8. assert len(enc) > 0
  9. dec = core.decrypt_string(enc, '12345')
  10. assert dec == 'abcdefg'
  11. # Test pre-encrypted bf-cbc string
  12. enc = b'[\x00\x10\x00d\x00\xb5\x7f\xc44Y\xb7\xd9\x15\xe3\xbd\xcf\xb3yK\xfb\xf6'
  13. assert 'test' == core.decrypt_string(enc, '98765')
  14. # Test pre-encrypted aes-256-cbc string
  15. enc = b'\xab\x01 \x00d\x00\xf1WP\xb0\x96h\xf8\xc5\xf4\x8d\x0b>q0\xf15\x185\xf8+\x1b\xe4\xae8\x88\xf2\x91\x15\xb8\x8fh\x88'
  16. assert 'test' == core.decrypt_string(enc, '98765')