Skip to content

Commit 7446f0a

Browse files
committed
rsa.pkcs1.verify() should return True when successful
- when verification passes verify() will return True, instead of None. If verification fails the function will still raise a rsa.pkcs1.VerificationError for legacy purposes. - update the docs to note that the verify() function returns True when successful - write unit tests to verify this new behavior This commit passes all build tests: Ran 44 tests in 1.217s OK
1 parent 14ba108 commit 7446f0a

4 files changed

Lines changed: 6 additions & 3 deletions

File tree

doc/usage.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,11 @@ possible, check the :py:func:`rsa.sign` function documentation for
197197
details. The hash is then signed with the private key.
198198

199199
In order to verify the signature, use the :py:func:`rsa.verify`
200-
function.
200+
function. This function returns True if the verification is successful:
201201

202202
>>> message = 'Go left at the blue tree'
203203
>>> rsa.verify(message, signature, pubkey)
204+
True
204205

205206
Modify the message, and the signature is no longer valid and a
206207
:py:class:`rsa.pkcs1.VerificationError` is thrown:

rsa/pkcs1.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ def verify(message, signature, pub_key):
321321
if message_hash != signature_hash:
322322
raise VerificationError('Verification failed')
323323

324+
return True
325+
324326
def _hash(message, method_name):
325327
'''Returns the message digest.
326328

tests/test_bigfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_sign_verify_bigfile(self):
5151

5252
# Check the signature
5353
msgfile.seek(0)
54-
pkcs1.verify(msgfile, signature, pub_key)
54+
self.assertTrue(pkcs1.verify(msgfile, signature, pub_key))
5555

5656
# Alter the message, re-check
5757
msgfile = BytesIO(b('123456sybren'))

tests/test_pkcs1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_sign_verify(self):
6464
signature = pkcs1.sign(message, self.priv, 'SHA-256')
6565
print("\tSignature: %r" % signature)
6666

67-
pkcs1.verify(message, signature, self.pub)
67+
self.assertTrue(pkcs1.verify(message, signature, self.pub))
6868

6969
def test_alter_message(self):
7070
'''Altering the message should let the verification fail.'''

0 commit comments

Comments
 (0)