1# -*- coding: utf-8 -*-
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#      https://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
17"""Tests integer operations."""
18
19import unittest
20
21import rsa
22import rsa.core
23
24
25class IntegerTest(unittest.TestCase):
26    def setUp(self):
27        (self.pub, self.priv) = rsa.newkeys(64)
28
29    def test_enc_dec(self):
30        message = 42
31        print("\tMessage:   %d" % message)
32
33        encrypted = rsa.core.encrypt_int(message, self.pub.e, self.pub.n)
34        print("\tEncrypted: %d" % encrypted)
35
36        decrypted = rsa.core.decrypt_int(encrypted, self.priv.d, self.pub.n)
37        print("\tDecrypted: %d" % decrypted)
38
39        self.assertEqual(message, decrypted)
40
41    def test_sign_verify(self):
42        message = 42
43
44        signed = rsa.core.encrypt_int(message, self.priv.d, self.pub.n)
45        print("\tSigned:    %d" % signed)
46
47        verified = rsa.core.decrypt_int(signed, self.pub.e, self.pub.n)
48        print("\tVerified:  %d" % verified)
49
50        self.assertEqual(message, verified)
51