Skip to content

Commit 0e190e9

Browse files
authored
Merge branch 'master' into decode-key-type-in-errors
2 parents 3fe6182 + e5a7d58 commit 0e190e9

File tree

4 files changed

+7
-31
lines changed

4 files changed

+7
-31
lines changed

.travis.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
language: python
22
python:
3-
- "2.7"
43
- "3.4"
54
- "3.5"
65
- "3.6"
7-
- "3.6-dev"
8-
- "3.7-dev"
6+
- "3.7"
97
- "nightly"
108
install:
119
- pip install -r requirements.txt

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
'Intended Audience :: System Administrators',
2323
'Topic :: Security',
2424
'License :: OSI Approved :: BSD License',
25-
'Programming Language :: Python :: 2.7',
2625
'Programming Language :: Python :: 3',
2726
'Programming Language :: Python :: 3.4',
2827
'Programming Language :: Python :: 3.5',

sshpubkeys/exceptions.py

-20
Original file line numberDiff line numberDiff line change
@@ -4,103 +4,83 @@
44

55
class InvalidKeyException(Exception):
66
"""Invalid key - something is wrong with the key, and it should not be accepted, as OpenSSH will not work with it."""
7-
pass
87

98

109
class InvalidKeyError(InvalidKeyException):
1110
"""Invalid key - something is wrong with the key, and it should not be accepted, as OpenSSH will not work with it."""
12-
pass
1311

1412

1513
class InvalidKeyLengthException(InvalidKeyError):
1614
"""Invalid key length - either too short or too long.
1715
1816
See also TooShortKeyException and TooLongKeyException."""
19-
pass
2017

2118

2219
class InvalidKeyLengthError(InvalidKeyError):
2320
"""Invalid key length - either too short or too long.
2421
2522
See also TooShortKeyException and TooLongKeyException."""
26-
pass
2723

2824

2925
class TooShortKeyException(InvalidKeyLengthError):
3026
"""Key is shorter than what the specification allow."""
31-
pass
3227

3328

3429
class TooShortKeyError(TooShortKeyException):
3530
"""Key is shorter than what the specification allows."""
36-
pass
3731

3832

3933
class TooLongKeyException(InvalidKeyLengthError):
4034
"""Key is longer than what the specification allows."""
41-
pass
4235

4336

4437
class TooLongKeyError(TooLongKeyException):
4538
"""Key is longer than what the specification allows."""
46-
pass
4739

4840

4941
class InvalidTypeException(InvalidKeyError):
5042
"""Key type is invalid or unrecognized."""
51-
pass
5243

5344

5445
class InvalidTypeError(InvalidTypeException):
5546
"""Key type is invalid or unrecognized."""
56-
pass
5747

5848

5949
class MalformedDataException(InvalidKeyError):
6050
"""The key is invalid - unable to parse the data. The data may be corrupted, truncated, or includes extra content that is not allowed."""
61-
pass
6251

6352

6453
class MalformedDataError(MalformedDataException):
6554
"""The key is invalid - unable to parse the data. The data may be corrupted, truncated, or includes extra content that is not allowed."""
66-
pass
6755

6856

6957
class InvalidOptionsException(MalformedDataError):
7058
"""Options string is invalid: it contains invalid characters, unrecognized options, or is otherwise malformed."""
71-
pass
7259

7360

7461
class InvalidOptionsError(InvalidOptionsException):
7562
"""Options string is invalid: it contains invalid characters, unrecognized options, or is otherwise malformed."""
76-
pass
7763

7864

7965
class InvalidOptionNameException(InvalidOptionsError):
8066
"""Invalid option name (contains disallowed characters, or is unrecognized.)."""
81-
pass
8267

8368

8469
class InvalidOptionNameError(InvalidOptionNameException):
8570
"""Invalid option name (contains disallowed characters, or is unrecognized.)."""
86-
pass
8771

8872

8973
class UnknownOptionNameException(InvalidOptionsError):
9074
"""Unrecognized option name."""
91-
pass
9275

9376

9477
class UnknownOptionNameError(UnknownOptionNameException):
9578
"""Unrecognized option name."""
96-
pass
9779

9880

9981
class MissingMandatoryOptionValueException(InvalidOptionsError):
10082
"""Mandatory option value is missing."""
101-
pass
10283

10384

10485
class MissingMandatoryOptionValueError(MissingMandatoryOptionValueException):
10586
"""Mandatory option value is missing."""
106-
pass

sshpubkeys/keys.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
__all__ = ["AuthorizedKeysFile", "SSHKey"]
3333

3434

35-
class AuthorizedKeysFile(object): # pylint:disable=too-few-public-methods
35+
class AuthorizedKeysFile: # pylint:disable=too-few-public-methods
3636
"""Represents a full authorized_keys file.
3737
3838
Comments and empty lines are ignored."""
@@ -53,7 +53,7 @@ def parse(self, file_obj, **kwargs):
5353
self.keys.append(ssh_key)
5454

5555

56-
class SSHKey(object): # pylint:disable=too-many-instance-attributes
56+
class SSHKey: # pylint:disable=too-many-instance-attributes
5757
"""Represents a single SSH keypair.
5858
5959
ssh_key = SSHKey(key_data, strict=True)
@@ -391,14 +391,13 @@ def _process_ed25516(self, data):
391391
def _process_key(self, data):
392392
if self.key_type == b"ssh-rsa":
393393
return self._process_ssh_rsa(data)
394-
elif self.key_type == b"ssh-dss":
394+
if self.key_type == b"ssh-dss":
395395
return self._process_ssh_dss(data)
396-
elif self.key_type.strip().startswith(b"ecdsa-sha"):
396+
if self.key_type.strip().startswith(b"ecdsa-sha"):
397397
return self._process_ecdsa_sha(data)
398-
elif self.key_type == b"ssh-ed25519":
398+
if self.key_type == b"ssh-ed25519":
399399
return self._process_ed25516(data)
400-
else:
401-
raise NotImplementedError("Invalid key type: %s" % self.key_type.decode())
400+
raise NotImplementedError("Invalid key type: %s" % self.key_type.decode())
402401

403402
def parse(self, keydata=None):
404403
"""Validates SSH public key.

0 commit comments

Comments
 (0)