mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
Improve code coverage for pycrypto_keys.py
This commit is contained in:
parent
f6b5927238
commit
55e9e952b6
2 changed files with 12 additions and 2 deletions
|
|
@ -66,6 +66,7 @@ def test_generate_rsa_public_and_private(self):
|
|||
|
||||
def test_create_rsa_signature(self):
|
||||
global private_rsa
|
||||
global public_rsa
|
||||
data = 'The quick brown fox jumps over the lazy dog'.encode('utf-8')
|
||||
signature, method = pycrypto.create_rsa_signature(private_rsa, data)
|
||||
|
||||
|
|
@ -83,9 +84,16 @@ def test_create_rsa_signature(self):
|
|||
pycrypto.create_rsa_signature, '', data)
|
||||
|
||||
# Check for invalid 'data'.
|
||||
print(repr(private_rsa))
|
||||
pycrypto.create_rsa_signature(private_rsa, '')
|
||||
|
||||
self.assertRaises(tuf.CryptoError,
|
||||
pycrypto.create_rsa_signature, private_rsa, 123)
|
||||
|
||||
# Check for missing private key.
|
||||
self.assertRaises(tuf.CryptoError,
|
||||
pycrypto.create_rsa_signature, public_rsa, data)
|
||||
|
||||
|
||||
def test_verify_rsa_signature(self):
|
||||
global public_rsa
|
||||
|
|
@ -209,6 +217,7 @@ def test_create_rsa_public_and_private_from_encrypted_pem(self):
|
|||
self.assertRaises(tuf.FormatError,
|
||||
pycrypto.create_rsa_public_and_private_from_encrypted_pem,
|
||||
pem_rsakey, ['pw'])
|
||||
|
||||
self.assertRaises(tuf.CryptoError,
|
||||
pycrypto.create_rsa_public_and_private_from_encrypted_pem,
|
||||
'invalid_pem', passphrase)
|
||||
|
|
|
|||
|
|
@ -585,8 +585,9 @@ def create_rsa_public_and_private_from_encrypted_pem(encrypted_pem, passphrase):
|
|||
public = rsa_pubkey.exportKey(format='PEM')
|
||||
|
||||
# PyCrypto raises 'ValueError' if the public or private keys cannot be
|
||||
# exported. See 'Crypto.PublicKey.RSA'.
|
||||
except (ValueError):
|
||||
# exported. See 'Crypto.PublicKey.RSA'. 'ValueError' should not be raised
|
||||
# if the 'Crypto.PublicKey.RSA.importKey() call above passed.
|
||||
except (ValueError): #pragma: no cover
|
||||
message = 'The public and private keys cannot be exported in PEM format.'
|
||||
raise tuf.CryptoError(message)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue