1#  Copyright 2011 Sybren A. Stüvel <[email protected]>
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
15"""Tests string operations."""
16
17from __future__ import absolute_import
18
19import unittest
20
21import rsa
22
23unicode_string = u"Euro=\u20ac ABCDEFGHIJKLMNOPQRSTUVWXYZ"
24
25
26class StringTest(unittest.TestCase):
27    def setUp(self):
28        (self.pub, self.priv) = rsa.newkeys(384)
29
30    def test_enc_dec(self):
31        message = unicode_string.encode('utf-8')
32        print("\tMessage:   %r" % message)
33
34        encrypted = rsa.encrypt(message, self.pub)
35        print("\tEncrypted: %r" % encrypted)
36
37        decrypted = rsa.decrypt(encrypted, self.priv)
38        print("\tDecrypted: %r" % decrypted)
39
40        self.assertEqual(message, decrypted)
41