blob: 28fa091a477103d0cdcfee2488eaf8375270eea3 [file] [log] [blame]
Sybren A. Stüvel9d2cd9a2015-11-05 19:53:38 +00001# -*- coding: utf-8 -*-
Roy Kokkelkoren0659aac2015-10-25 16:12:11 +01002#
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#
Sybren A. Stüvel3934ab42016-02-05 16:01:20 +01009# https://www.apache.org/licenses/LICENSE-2.0
Roy Kokkelkoren0659aac2015-10-25 16:12:11 +010010#
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
Sybren A. Stüveld3d10342016-01-22 11:36:06 +010017"""Tests string operations."""
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020018
Yesudeep Mangalapilly58024312011-08-11 01:48:25 +053019from __future__ import absolute_import
20
Sybren A. Stüveled1c81d2016-01-14 12:23:32 +010021import unittest
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020022
23import rsa
24
Sybren A. Stüveldd5e9792016-01-27 15:54:47 +010025unicode_string = u"Euro=\u20ac ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Yesudeep Mangalapilly58024312011-08-11 01:48:25 +053026
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020027
Sybren A. Stüveld3d10342016-01-22 11:36:06 +010028class StringTest(unittest.TestCase):
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020029 def setUp(self):
Sybren A. Stüvel8c857f42011-07-30 20:39:02 +020030 (self.pub, self.priv) = rsa.newkeys(384)
Sybren A. Stüvelff3a1d02011-06-20 00:13:53 +020031
32 def test_enc_dec(self):
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)