Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
name: Run python tests

on: [push]
on:
push:
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pycodestyle isort pylint yapf
pip install pycodestyle isort pylint pytest setuptools yapf
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
echo "PYTHONPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
- name: Check pycodestyle
run: |
pycodestyle --ignore E501,E402 --exclude=.git,dev3 sshpubkeys tests
Expand All @@ -29,7 +32,7 @@ jobs:
pylint sshpubkeys tests
- name: Run tests
run: |
python3 setup.py test
pytest
- name: Check formatting
run: |
isort --recursive sshpubkeys tests; yapf --recursive -i .
Expand Down
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
minversion = 8.3.0
addopts = -ra -q
testpaths = tests
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cryptography==3.3.2
yapf==0.21.0
cryptography==43.0.0
yapf==0.43.0
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='sshpubkeys',
version='3.3.1',
version='3.4.0',
description='SSH public key parser',
long_description=long_description,
url='https://github.com/ojarva/python-sshpubkeys',
Expand All @@ -32,7 +32,9 @@
packages=["sshpubkeys"],
test_suite="tests",
python_requires='>=3',
install_requires=['cryptography>=2.5'],
install_requires=['cryptography==43.0.0'],
setup_requires=['setuptools', 'pytest-runner'],
tests_require=['pytest'],
extras_require={
'dev': ['twine', 'wheel', 'yapf'],
},
Expand Down
10 changes: 4 additions & 6 deletions sshpubkeys/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
class _ECVerifyingKey:
"""ecdsa.key.VerifyingKey reimplementation
"""

def __init__(self, pubkey, default_hashfunc):
self.pubkey = pubkey
self.default_hashfunc = default_hashfunc
Expand All @@ -57,9 +56,9 @@ def __repr__(self):
def to_string(self, encoding="raw"):
"""Pub key as bytes string"""
if encoding == "raw":
return self.pubkey.public_numbers().encode_point()[1:]
return self.pubkey.public_bytes(Encoding.X962, PublicFormat.UncompressedPoint)[1:]
if encoding == "uncompressed":
return self.pubkey.public_numbers().encode_point()
return self.pubkey.public_bytes(Encoding.X962, PublicFormat.UncompressedPoint)
if encoding == "compressed":
return self.pubkey.public_bytes(Encoding.X962, PublicFormat.CompressedPoint)
raise ValueError(encoding)
Expand All @@ -85,7 +84,6 @@ class AuthorizedKeysFile: # pylint:disable=too-few-public-methods
"""Represents a full authorized_keys file.

Comments and empty lines are ignored."""

def __init__(self, file_obj, **kwargs):
self.keys = []
self.parse(file_obj, **kwargs)
Expand Down Expand Up @@ -201,7 +199,7 @@ def hash(self):

Deprecated, use .hash_md5() instead."""
warnings.warn("hash() is deprecated. Use hash_md5(), hash_sha256() or hash_sha512() instead.")
return self.hash_md5().replace(b"MD5:", b"")
return self.hash_md5().replace("MD5:", "")

def hash_md5(self):
"""Calculate md5 fingerprint.
Expand Down Expand Up @@ -249,7 +247,7 @@ def _parse_long(cls, data):
"""Calculate two's complement."""
if sys.version < '3':
# this does not exist in python 3 - undefined-variable disabled to make pylint happier.
ret = long(0) # pylint:disable=undefined-variable
ret = 0 # pylint:disable=undefined-variable
for byte in data:
ret = (ret << 8) + ord(byte)
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/authorized_keys.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .valid_keys import keys
from valid_keys import keys

items = [
["empty_file", "", 0],
Expand Down
4 changes: 2 additions & 2 deletions tests/invalid_authorized_keys.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .invalid_keys import keys as invalid_keys
from .valid_keys import keys as valid_keys
from invalid_keys import keys as invalid_keys
from sshpubkeys.exceptions import InvalidKeyError, MalformedDataError
from valid_keys import keys as valid_keys

items = [
["lines_with_spaces", " # Comments\n \n" + valid_keys[0][0] + "\nasdf", InvalidKeyError],
Expand Down
21 changes: 9 additions & 12 deletions tests/__init__.py → tests/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

"""

from .authorized_keys import items as list_of_authorized_keys
from .invalid_authorized_keys import items as list_of_invalid_authorized_keys
from .invalid_keys import keys as list_of_invalid_keys
from .invalid_options import options as list_of_invalid_options
from .valid_keys import keys as list_of_valid_keys
from .valid_keys_rfc4716 import keys as list_of_valid_keys_rfc4716
from .valid_options import options as list_of_valid_options
from authorized_keys import items as list_of_authorized_keys
from invalid_authorized_keys import items as list_of_invalid_authorized_keys
from invalid_keys import keys as list_of_invalid_keys
from invalid_options import options as list_of_invalid_options
from sshpubkeys import AuthorizedKeysFile, InvalidOptionsError, SSHKey
from valid_keys import keys as list_of_valid_keys
from valid_keys_rfc4716 import keys as list_of_valid_keys_rfc4716
from valid_options import options as list_of_valid_options

import sys
import unittest
Expand All @@ -32,7 +32,7 @@ def test_none_to_constructor(self):


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

def loop_options(options):
""" Loop over list of options and dynamically create tests """

def ch(option, parsed_option):
return lambda self: self.check_valid_option(option, parsed_option)

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

def loop_valid(keyset, prefix):
""" Loop over list of valid keys and dynamically create tests """

def ch(pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kwargs): # pylint:disable=too-many-arguments
def ch(pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kwargs): # pylint: disable=too-many-positional-arguments,too-many-arguments
return lambda self: self.check_key(pubkey, bits, fingerprint_md5, fingerprint_sha256, options, comment, **kwargs)

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

def loop_invalid(keyset, prefix):
""" Loop over list of invalid keys and dynamically create tests """

def ch(pubkey, expected_error, **kwargs):
return lambda self: self.check_fail(pubkey, expected_error, **kwargs)

Expand Down
Loading