test_strings.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright 2011 Sybren A. Stüvel <sybren@stuvel.eu>
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # https://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Tests string operations."""
  15. from __future__ import absolute_import
  16. import unittest
  17. import rsa
  18. unicode_string = u"Euro=\u20ac ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  19. class StringTest(unittest.TestCase):
  20. def setUp(self):
  21. (self.pub, self.priv) = rsa.newkeys(384)
  22. def test_enc_dec(self):
  23. message = unicode_string.encode("utf-8")
  24. print("\n\tMessage: %r" % message)
  25. encrypted = rsa.encrypt(message, self.pub)
  26. print("\tEncrypted: %r" % encrypted)
  27. decrypted = rsa.decrypt(encrypted, self.priv)
  28. print("\tDecrypted: %r" % decrypted)
  29. self.assertEqual(message, decrypted)