Roy Kokkelkoren | 0659aac | 2015-10-25 16:12:11 +0100 | [diff] [blame] | 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 | # |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 7 | # https://www.apache.org/licenses/LICENSE-2.0 |
Roy Kokkelkoren | 0659aac | 2015-10-25 16:12:11 +0100 | [diff] [blame] | 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 | |
Sybren A. Stüvel | d3d1034 | 2016-01-22 11:36:06 +0100 | [diff] [blame] | 15 | """Tests string operations.""" |
Sybren A. Stüvel | ff3a1d0 | 2011-06-20 00:13:53 +0200 | [diff] [blame] | 16 | |
Yesudeep Mangalapilly | 5802431 | 2011-08-11 01:48:25 +0530 | [diff] [blame] | 17 | from __future__ import absolute_import |
| 18 | |
Sybren A. Stüvel | ed1c81d | 2016-01-14 12:23:32 +0100 | [diff] [blame] | 19 | import unittest |
Sybren A. Stüvel | ff3a1d0 | 2011-06-20 00:13:53 +0200 | [diff] [blame] | 20 | |
| 21 | import rsa |
| 22 | |
Sybren A. Stüvel | dd5e979 | 2016-01-27 15:54:47 +0100 | [diff] [blame] | 23 | unicode_string = u"Euro=\u20ac ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
Yesudeep Mangalapilly | 5802431 | 2011-08-11 01:48:25 +0530 | [diff] [blame] | 24 | |
Sybren A. Stüvel | ff3a1d0 | 2011-06-20 00:13:53 +0200 | [diff] [blame] | 25 | |
Sybren A. Stüvel | d3d1034 | 2016-01-22 11:36:06 +0100 | [diff] [blame] | 26 | class StringTest(unittest.TestCase): |
Sybren A. Stüvel | ff3a1d0 | 2011-06-20 00:13:53 +0200 | [diff] [blame] | 27 | def setUp(self): |
Sybren A. Stüvel | 8c857f4 | 2011-07-30 20:39:02 +0200 | [diff] [blame] | 28 | (self.pub, self.priv) = rsa.newkeys(384) |
Sybren A. Stüvel | ff3a1d0 | 2011-06-20 00:13:53 +0200 | [diff] [blame] | 29 | |
| 30 | def test_enc_dec(self): |
Yesudeep Mangalapilly | 5802431 | 2011-08-11 01:48:25 +0530 | [diff] [blame] | 31 | message = unicode_string.encode('utf-8') |
Jon Dufresne | 7424c69 | 2018-10-10 05:48:54 -0700 | [diff] [blame] | 32 | print("\tMessage: %r" % message) |
Sybren A. Stüvel | ff3a1d0 | 2011-06-20 00:13:53 +0200 | [diff] [blame] | 33 | |
| 34 | encrypted = rsa.encrypt(message, self.pub) |
Jon Dufresne | 7424c69 | 2018-10-10 05:48:54 -0700 | [diff] [blame] | 35 | print("\tEncrypted: %r" % encrypted) |
Sybren A. Stüvel | ff3a1d0 | 2011-06-20 00:13:53 +0200 | [diff] [blame] | 36 | |
| 37 | decrypted = rsa.decrypt(encrypted, self.priv) |
Jon Dufresne | 7424c69 | 2018-10-10 05:48:54 -0700 | [diff] [blame] | 38 | print("\tDecrypted: %r" % decrypted) |
Sybren A. Stüvel | ff3a1d0 | 2011-06-20 00:13:53 +0200 | [diff] [blame] | 39 | |
| 40 | self.assertEqual(message, decrypted) |