Skip to content

Commit 4a18769

Browse files
author
Abhinav Akash
committed
Update cryptography dependency, add pytest and bump the package version to 3.4.0
1 parent 5f78869 commit 4a18769

File tree

11 files changed

+485
-383
lines changed

11 files changed

+485
-383
lines changed

.github/workflows/python-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v4
1717
- name: Set up Python
18-
uses: actions/setup-python@v2
18+
uses: actions/setup-python@v5
1919
with:
2020
python-version: '3.x'
2121
- name: Install dependencies

.github/workflows/python-tests.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
name: Run python tests
22

3-
on: [push]
3+
on:
4+
push:
5+
workflow_dispatch:
46

57
jobs:
68
build:
79

810
runs-on: ubuntu-latest
911
strategy:
1012
matrix:
11-
python-version: ["3.9", "3.10", "3.11"]
13+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
1214

1315
steps:
14-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v4
1517
- name: Set up Python ${{ matrix.python-version }}
16-
uses: actions/setup-python@v2
18+
uses: actions/setup-python@v5
1719
with:
1820
python-version: ${{ matrix.python-version }}
1921
- name: Install dependencies
2022
run: |
2123
python -m pip install --upgrade pip
22-
pip install pycodestyle isort pylint yapf
24+
pip install pycodestyle isort pylint pytest setuptools yapf
2325
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
26+
echo "PYTHONPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
2427
- name: Check pycodestyle
2528
run: |
2629
pycodestyle --ignore E501,E402 --exclude=.git,dev3 sshpubkeys tests
@@ -29,7 +32,7 @@ jobs:
2932
pylint sshpubkeys tests
3033
- name: Run tests
3134
run: |
32-
python3 setup.py test
35+
pytest
3336
- name: Check formatting
3437
run: |
3538
isort --recursive sshpubkeys tests; yapf --recursive -i .

pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[pytest]
2+
minversion = 8.3.0
3+
addopts = -ra -q
4+
testpaths = tests

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
cryptography==3.3.2
2-
yapf==0.21.0
1+
cryptography==43.0.0
2+
yapf==0.43.0

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setup(
1111
name='sshpubkeys',
12-
version='3.3.1',
12+
version='3.4.0',
1313
description='SSH public key parser',
1414
long_description=long_description,
1515
url='https://github.com/ojarva/python-sshpubkeys',
@@ -32,7 +32,9 @@
3232
packages=["sshpubkeys"],
3333
test_suite="tests",
3434
python_requires='>=3',
35-
install_requires=['cryptography>=2.5'],
35+
install_requires=['cryptography==43.0.0'],
36+
setup_requires=['setuptools', 'pytest-runner'],
37+
tests_require=['pytest'],
3638
extras_require={
3739
'dev': ['twine', 'wheel', 'yapf'],
3840
},

sshpubkeys/keys.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
class _ECVerifyingKey:
4040
"""ecdsa.key.VerifyingKey reimplementation
4141
"""
42-
4342
def __init__(self, pubkey, default_hashfunc):
4443
self.pubkey = pubkey
4544
self.default_hashfunc = default_hashfunc
@@ -57,9 +56,9 @@ def __repr__(self):
5756
def to_string(self, encoding="raw"):
5857
"""Pub key as bytes string"""
5958
if encoding == "raw":
60-
return self.pubkey.public_numbers().encode_point()[1:]
59+
return self.pubkey.public_bytes(Encoding.X962, PublicFormat.UncompressedPoint)[1:]
6160
if encoding == "uncompressed":
62-
return self.pubkey.public_numbers().encode_point()
61+
return self.pubkey.public_bytes(Encoding.X962, PublicFormat.UncompressedPoint)
6362
if encoding == "compressed":
6463
return self.pubkey.public_bytes(Encoding.X962, PublicFormat.CompressedPoint)
6564
raise ValueError(encoding)
@@ -85,7 +84,6 @@ class AuthorizedKeysFile: # pylint:disable=too-few-public-methods
8584
"""Represents a full authorized_keys file.
8685
8786
Comments and empty lines are ignored."""
88-
8987
def __init__(self, file_obj, **kwargs):
9088
self.keys = []
9189
self.parse(file_obj, **kwargs)
@@ -201,7 +199,7 @@ def hash(self):
201199
202200
Deprecated, use .hash_md5() instead."""
203201
warnings.warn("hash() is deprecated. Use hash_md5(), hash_sha256() or hash_sha512() instead.")
204-
return self.hash_md5().replace(b"MD5:", b"")
202+
return self.hash_md5().replace("MD5:", "")
205203

206204
def hash_md5(self):
207205
"""Calculate md5 fingerprint.
@@ -249,7 +247,7 @@ def _parse_long(cls, data):
249247
"""Calculate two's complement."""
250248
if sys.version < '3':
251249
# this does not exist in python 3 - undefined-variable disabled to make pylint happier.
252-
ret = long(0) # pylint:disable=undefined-variable
250+
ret = 0 # pylint:disable=undefined-variable
253251
for byte in data:
254252
ret = (ret << 8) + ord(byte)
255253
else:

tests/authorized_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .valid_keys import keys
1+
from valid_keys import keys
22

33
items = [
44
["empty_file", "", 0],

tests/invalid_authorized_keys.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from .invalid_keys import keys as invalid_keys
2-
from .valid_keys import keys as valid_keys
1+
from invalid_keys import keys as invalid_keys
32
from sshpubkeys.exceptions import InvalidKeyError, MalformedDataError
3+
from valid_keys import keys as valid_keys
44

55
items = [
66
["lines_with_spaces", " # Comments\n \n" + valid_keys[0][0] + "\nasdf", InvalidKeyError],
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
55
"""
66

7-
from .authorized_keys import items as list_of_authorized_keys
8-
from .invalid_authorized_keys import items as list_of_invalid_authorized_keys
9-
from .invalid_keys import keys as list_of_invalid_keys
10-
from .invalid_options import options as list_of_invalid_options
11-
from .valid_keys import keys as list_of_valid_keys
12-
from .valid_keys_rfc4716 import keys as list_of_valid_keys_rfc4716
13-
from .valid_options import options as list_of_valid_options
7+
from authorized_keys import items as list_of_authorized_keys
8+
from invalid_authorized_keys import items as list_of_invalid_authorized_keys
9+
from invalid_keys import keys as list_of_invalid_keys
10+
from invalid_options import options as list_of_invalid_options
1411
from sshpubkeys import AuthorizedKeysFile, InvalidOptionsError, SSHKey
12+
from valid_keys import keys as list_of_valid_keys
13+
from valid_keys_rfc4716 import keys as list_of_valid_keys_rfc4716
14+
from valid_options import options as list_of_valid_options
1515

1616
import sys
1717
import unittest
@@ -32,7 +32,7 @@ def test_none_to_constructor(self):
3232

3333

3434
class TestKeys(unittest.TestCase):
35-
def check_key(self, pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kwargs): # pylint:disable=too-many-arguments
35+
def check_key(self, pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kwargs): # pylint: disable=too-many-positional-arguments,too-many-arguments
3636
""" Checks valid key """
3737
ssh = SSHKey(pubkey, **kwargs)
3838
ssh.parse()
@@ -100,7 +100,6 @@ def test_disallow_options(self):
100100

101101
def loop_options(options):
102102
""" Loop over list of options and dynamically create tests """
103-
104103
def ch(option, parsed_option):
105104
return lambda self: self.check_valid_option(option, parsed_option)
106105

@@ -120,8 +119,7 @@ def ch(option, expected_error):
120119

121120
def loop_valid(keyset, prefix):
122121
""" Loop over list of valid keys and dynamically create tests """
123-
124-
def ch(pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kwargs): # pylint:disable=too-many-arguments
122+
def ch(pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kwargs): # pylint: disable=too-many-positional-arguments,too-many-arguments
125123
return lambda self: self.check_key(pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kwargs)
126124

127125
for items in keyset:
@@ -145,7 +143,6 @@ def ch(pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kw
145143

146144
def loop_invalid(keyset, prefix):
147145
""" Loop over list of invalid keys and dynamically create tests """
148-
149146
def ch(pubkey, expected_error, **kwargs):
150147
return lambda self: self.check_fail(pubkey, expected_error, **kwargs)
151148

0 commit comments

Comments
 (0)