diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2016-01-22 11:36:06 +0100 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2016-01-22 11:36:06 +0100 |
commit | d3d10345b47c2b17922bb91059cfceea82f82338 (patch) | |
tree | 6a336d74ee41a4ba98b6b3d97f123cd0c5f4e9b7 /tests/test_pkcs1.py | |
parent | 541ee468b6b33c7ae27818bbfea63df9622f9d8a (diff) | |
download | rsa-git-d3d10345b47c2b17922bb91059cfceea82f82338.tar.gz |
Big refactor to become more PEP8 compliant.
Mostly focused on docstrings (''' → """), indentation, empty lines,
and superfluous parenthesis.
Diffstat (limited to 'tests/test_pkcs1.py')
-rw-r--r-- | tests/test_pkcs1.py | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/tests/test_pkcs1.py b/tests/test_pkcs1.py index 7b92197..1bff0fb 100644 --- a/tests/test_pkcs1.py +++ b/tests/test_pkcs1.py @@ -14,22 +14,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -'''Tests string operations.''' +"""Tests string operations.""" import struct import unittest import rsa from rsa import pkcs1 -from rsa._compat import byte, is_integer, b, is_bytes +from rsa._compat import byte, b, is_bytes -class BinaryTest(unittest.TestCase): +class BinaryTest(unittest.TestCase): def setUp(self): (self.pub, self.priv) = rsa.newkeys(256) def test_enc_dec(self): - message = struct.pack('>IIII', 0, 0, 0, 1) print("\tMessage: %r" % message) @@ -42,7 +41,6 @@ class BinaryTest(unittest.TestCase): self.assertEqual(message, decrypted) def test_decoding_failure(self): - message = struct.pack('>IIII', 0, 0, 0, 1) encrypted = pkcs1.encrypt(message, self.pub) @@ -51,29 +49,29 @@ class BinaryTest(unittest.TestCase): if is_bytes(a): a = ord(a) encrypted = encrypted[:5] + byte(a + 1) + encrypted[6:] - + self.assertRaises(pkcs1.DecryptionError, pkcs1.decrypt, encrypted, self.priv) def test_randomness(self): - '''Encrypting the same message twice should result in different + """Encrypting the same message twice should result in different cryptos. - ''' - + """ + message = struct.pack('>IIII', 0, 0, 0, 1) encrypted1 = pkcs1.encrypt(message, self.pub) encrypted2 = pkcs1.encrypt(message, self.pub) - + self.assertNotEqual(encrypted1, encrypted2) -class SignatureTest(unittest.TestCase): +class SignatureTest(unittest.TestCase): def setUp(self): (self.pub, self.priv) = rsa.newkeys(512) def test_sign_verify(self): - '''Test happy flow of sign and verify''' - + """Test happy flow of sign and verify""" + message = b('je moeder') print("\tMessage: %r" % message) @@ -83,28 +81,27 @@ class SignatureTest(unittest.TestCase): self.assertTrue(pkcs1.verify(message, signature, self.pub)) def test_alter_message(self): - '''Altering the message should let the verification fail.''' - + """Altering the message should let the verification fail.""" + signature = pkcs1.sign(b('je moeder'), self.priv, 'SHA-256') self.assertRaises(pkcs1.VerificationError, pkcs1.verify, b('mijn moeder'), signature, self.pub) def test_sign_different_key(self): - '''Signing with another key should let the verification fail.''' - + """Signing with another key should let the verification fail.""" + (otherpub, _) = rsa.newkeys(512) - + message = b('je moeder') signature = pkcs1.sign(message, self.priv, 'SHA-256') self.assertRaises(pkcs1.VerificationError, pkcs1.verify, message, signature, otherpub) def test_multiple_signings(self): - '''Signing the same message twice should return the same signatures.''' - + """Signing the same message twice should return the same signatures.""" + message = struct.pack('>IIII', 0, 0, 0, 1) signature1 = pkcs1.sign(message, self.priv, 'SHA-1') signature2 = pkcs1.sign(message, self.priv, 'SHA-1') - - self.assertEqual(signature1, signature2) + self.assertEqual(signature1, signature2) |