blob: 1090a8e1dac33cc39961820f35862d6d73b34974 [file] [log] [blame]
Roy Kokkelkoren0659aac2015-10-25 16:12:11 +01001# 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#
Sybren A. Stüvel3934ab42016-02-05 16:01:20 +01007# https://www.apache.org/licenses/LICENSE-2.0
Roy Kokkelkoren0659aac2015-10-25 16:12:11 +01008#
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
Sybren A. Stüveld3d10342016-01-22 11:36:06 +010015"""Tests string operations."""
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020016
Yesudeep Mangalapilly58024312011-08-11 01:48:25 +053017from __future__ import absolute_import
18
Sybren A. Stüveled1c81d2016-01-14 12:23:32 +010019import unittest
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020020
21import rsa
22
Sybren A. Stüveldd5e9792016-01-27 15:54:47 +010023unicode_string = u"Euro=\u20ac ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Yesudeep Mangalapilly58024312011-08-11 01:48:25 +053024
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020025
Sybren A. Stüveld3d10342016-01-22 11:36:06 +010026class StringTest(unittest.TestCase):
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020027 def setUp(self):
Sybren A. Stüvel8c857f42011-07-30 20:39:02 +020028 (self.pub, self.priv) = rsa.newkeys(384)
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020029
30 def test_enc_dec(self):
Yesudeep Mangalapilly58024312011-08-11 01:48:25 +053031 message = unicode_string.encode('utf-8')
Jon Dufresne7424c692018-10-10 05:48:54 -070032 print("\tMessage: %r" % message)
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020033
34 encrypted = rsa.encrypt(message, self.pub)
Jon Dufresne7424c692018-10-10 05:48:54 -070035 print("\tEncrypted: %r" % encrypted)
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020036
37 decrypted = rsa.decrypt(encrypted, self.priv)
Jon Dufresne7424c692018-10-10 05:48:54 -070038 print("\tDecrypted: %r" % decrypted)
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020039
40 self.assertEqual(message, decrypted)