blob: e307efbe968b0f622a0e7ac96743b9cb70a60cf9 [file] [log] [blame]
Roy Kokkelkoren0659aac2015-10-25 16:12:11 +01001#
2# Copyright 2011 Sybren A. Stüvel <sybren@stuvel.eu>
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
Yesudeep Mangalapillyb5bab222011-08-24 16:53:39 +053016'''Tests string operations.'''
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020017
Yesudeep Mangalapilly58024312011-08-11 01:48:25 +053018from __future__ import absolute_import
19
Yesudeep Mangalapillyaed6e862011-08-11 01:59:50 +053020import unittest2
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020021
22import rsa
23
Sybren A. Stüvel15e257a2011-11-06 10:11:51 +010024from constants import unicode_string
Yesudeep Mangalapilly58024312011-08-11 01:48:25 +053025
Yesudeep Mangalapillyaed6e862011-08-11 01:59:50 +053026class StringTest(unittest2.TestCase):
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020027
28 def setUp(self):
Sybren A. Stüvel8c857f42011-07-30 20:39:02 +020029 (self.pub, self.priv) = rsa.newkeys(384)
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020030
31 def test_enc_dec(self):
32
Yesudeep Mangalapilly58024312011-08-11 01:48:25 +053033 message = unicode_string.encode('utf-8')
34 print("\tMessage: %s" % message)
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020035
36 encrypted = rsa.encrypt(message, self.pub)
Yesudeep Mangalapilly58024312011-08-11 01:48:25 +053037 print("\tEncrypted: %s" % encrypted)
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020038
39 decrypted = rsa.decrypt(encrypted, self.priv)
Yesudeep Mangalapilly58024312011-08-11 01:48:25 +053040 print("\tDecrypted: %s" % decrypted)
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020041
42 self.assertEqual(message, decrypted)
43