|
13 | 13 | sys.exit(1) |
14 | 14 | print(ssh_key.bits)""" |
15 | 15 |
|
16 | | -from .exceptions import (InvalidKeyError, InvalidKeyLengthError, InvalidOptionNameError, InvalidOptionsError, |
17 | | - InvalidTypeError, MalformedDataError, MissingMandatoryOptionValueError, TooLongKeyError, |
18 | | - TooShortKeyError, UnknownOptionNameError) |
| 16 | +from .exceptions import ( |
| 17 | + InvalidKeyError, InvalidKeyLengthError, InvalidOptionNameError, InvalidOptionsError, InvalidTypeError, |
| 18 | + MalformedDataError, MissingMandatoryOptionValueError, TooLongKeyError, TooShortKeyError, UnknownOptionNameError |
| 19 | +) |
19 | 20 | from cryptography.hazmat.backends import default_backend |
20 | 21 | from cryptography.hazmat.primitives.asymmetric.dsa import DSAParameterNumbers, DSAPublicNumbers |
21 | 22 | from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicNumbers |
@@ -341,7 +342,9 @@ def _process_ssh_dss(self, data): |
341 | 342 | min_length = self.DSA_MIN_LENGTH_LOOSE |
342 | 343 | max_length = self.DSA_MAX_LENGTH_LOOSE |
343 | 344 | if p_bits < min_length: |
344 | | - raise TooShortKeyError("%s key can not be shorter than %s bits (was %s)" % (self.key_type.decode(), min_length, p_bits)) |
| 345 | + raise TooShortKeyError( |
| 346 | + "%s key can not be shorter than %s bits (was %s)" % (self.key_type.decode(), min_length, p_bits) |
| 347 | + ) |
345 | 348 | if p_bits > max_length: |
346 | 349 | raise TooLongKeyError( |
347 | 350 | "%s key data can not be longer than %s bits (was %s)" % (self.key_type.decode(), max_length, p_bits) |
@@ -396,8 +399,8 @@ def _validate_application_string(self, application): |
396 | 399 |
|
397 | 400 | try: |
398 | 401 | parsed_url = urlparse(application) |
399 | | - except ValueError as error: |
400 | | - raise InvalidKeyError("Application string: %s" % error) |
| 402 | + except ValueError as err: |
| 403 | + raise InvalidKeyError(f"Application string: {err}") from err |
401 | 404 | if parsed_url.scheme != b"ssh": |
402 | 405 | raise InvalidKeyError('Application string must begin with "ssh:"') |
403 | 406 |
|
|
0 commit comments