Sybren A. Stüvel | 9d2cd9a | 2015-11-05 19:53:38 +0000 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
Roy Kokkelkoren | 0659aac | 2015-10-25 16:12:11 +0100 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2011 Sybren A. Stüvel <sybren@stuvel.eu> |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
Yesudeep Mangalapilly | b5bab22 | 2011-08-24 16:53:39 +0530 | [diff] [blame] | 17 | '''Tests string operations.''' |
Sybren A. Stüvel | ff3a1d0 | 2011-06-20 00:13:53 +0200 | [diff] [blame] | 18 | |
Yesudeep Mangalapilly | 5802431 | 2011-08-11 01:48:25 +0530 | [diff] [blame] | 19 | from __future__ import absolute_import |
| 20 | |
Sybren A. Stüvel | ed1c81d | 2016-01-14 12:23:32 +0100 | [diff] [blame^] | 21 | import unittest |
Sybren A. Stüvel | ff3a1d0 | 2011-06-20 00:13:53 +0200 | [diff] [blame] | 22 | |
| 23 | import rsa |
| 24 | |
Sybren A. Stüvel | 15e257a | 2011-11-06 10:11:51 +0100 | [diff] [blame] | 25 | from constants import unicode_string |
Yesudeep Mangalapilly | 5802431 | 2011-08-11 01:48:25 +0530 | [diff] [blame] | 26 | |
Sybren A. Stüvel | ed1c81d | 2016-01-14 12:23:32 +0100 | [diff] [blame^] | 27 | class StringTest(unittest.TestCase): |
Sybren A. Stüvel | ff3a1d0 | 2011-06-20 00:13:53 +0200 | [diff] [blame] | 28 | |
| 29 | def setUp(self): |
Sybren A. Stüvel | 8c857f4 | 2011-07-30 20:39:02 +0200 | [diff] [blame] | 30 | (self.pub, self.priv) = rsa.newkeys(384) |
Sybren A. Stüvel | ff3a1d0 | 2011-06-20 00:13:53 +0200 | [diff] [blame] | 31 | |
| 32 | def test_enc_dec(self): |
| 33 | |
Yesudeep Mangalapilly | 5802431 | 2011-08-11 01:48:25 +0530 | [diff] [blame] | 34 | message = unicode_string.encode('utf-8') |
| 35 | print("\tMessage: %s" % message) |
Sybren A. Stüvel | ff3a1d0 | 2011-06-20 00:13:53 +0200 | [diff] [blame] | 36 | |
| 37 | encrypted = rsa.encrypt(message, self.pub) |
Yesudeep Mangalapilly | 5802431 | 2011-08-11 01:48:25 +0530 | [diff] [blame] | 38 | print("\tEncrypted: %s" % encrypted) |
Sybren A. Stüvel | ff3a1d0 | 2011-06-20 00:13:53 +0200 | [diff] [blame] | 39 | |
| 40 | decrypted = rsa.decrypt(encrypted, self.priv) |
Yesudeep Mangalapilly | 5802431 | 2011-08-11 01:48:25 +0530 | [diff] [blame] | 41 | print("\tDecrypted: %s" % decrypted) |
Sybren A. Stüvel | ff3a1d0 | 2011-06-20 00:13:53 +0200 | [diff] [blame] | 42 | |
| 43 | self.assertEqual(message, decrypted) |
| 44 | |