Skip to content

Commit 7162761

Browse files
committed
Remove redundant exception handling in keys module
Now that the low-level modules handling interaction with the cryptographic libraries handle missing imports and throw UnsupportedLibraryException at the function level it's no longer required to wrap their import in a try/except block. Signed-off-by: Joshua Lock <jlock@vmware.com>
1 parent c32ba17 commit 7162761

File tree

1 file changed

+2
-37
lines changed

1 file changed

+2
-37
lines changed

securesystemslib/keys.py

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -65,44 +65,9 @@
6565
import warnings
6666
import logging
6767

68-
# Try to import the pyca/Cryptography module (rsa_keys.py), which is
69-
# used for general-purpose cryptography and generation of RSA keys and
70-
# signatures.
71-
try:
72-
import securesystemslib.rsa_keys
73-
74-
except ImportError: #pragma: no cover
75-
pass
76-
77-
# Import the PyNaCl library, if available. It is recommended this library be
78-
# used over the pure python implementation of ed25519, due to its speedier
79-
# routines and side-channel protections available in the libsodium library.
80-
81-
# NOTE: Version 0.2.3 of 'pynacl' prints: "UserWarning: reimporting '...' might
82-
# overwrite older definitions." when importing 'nacl.signing' below. Suppress
83-
# user warnings temporarily (at least until this issue is fixed).
84-
with warnings.catch_warnings():
85-
warnings.simplefilter('ignore')
86-
try:
87-
import nacl
88-
import nacl.signing
89-
USE_PYNACL = True
90-
91-
# PyNaCl's 'cffi' dependency may raise an 'IOError' exception when importing
92-
# 'nacl.signing'.
93-
except (ImportError, IOError): # pragma: no cover
94-
USE_PYNACL = False
95-
pass
96-
97-
# The optimized version of the Ed25519 library provided by default is imported
98-
# regardless of the availability of PyNaCl.
68+
import securesystemslib.rsa_keys
9969
import securesystemslib.ed25519_keys
100-
101-
try:
102-
import securesystemslib.ecdsa_keys
103-
104-
except ImportError: #pragma: no cover
105-
pass
70+
import securesystemslib.ecdsa_keys
10671

10772
import securesystemslib.exceptions
10873

0 commit comments

Comments
 (0)