Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Python 3.12 and drop EOL 3.7 #223

Merged
merged 11 commits into from Nov 1, 2023
7 changes: 4 additions & 3 deletions .github/workflows/tests.yml
@@ -1,6 +1,6 @@
name: Test Python-RSA

on: [push]
on: [push, pull_request, workflow_dispatch]

permissions:
contents: read
Expand All @@ -11,20 +11,21 @@ jobs:
strategy:
matrix:
python-version:
- "3.7"
- "3.8"
- "pypy3.8"
- "3.9"
- "pypy3.9"
- "3.10"
- "pypy3.10"
- "3.11"
- "3.12"

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Expand Up @@ -6,7 +6,6 @@ cache: pip
# See: https://github.com/travis-ci/travis-ci/issues/3024

python:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
Expand All @@ -18,7 +17,7 @@ install:
- poetry install

script:
- poetry run py.test tests/
- poetry run pytest tests/

after_success:
- poetry run coveralls
12 changes: 6 additions & 6 deletions doc/conf.py
Expand Up @@ -43,8 +43,8 @@
master_doc = 'index'

# General information about the project.
project = u'Python-RSA'
copyright = u'2011-2019, Sybren A. Stüvel'
project = 'Python-RSA'
hugovk marked this conversation as resolved.
Show resolved Hide resolved
copyright = '2011-2019, Sybren A. Stüvel'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -180,8 +180,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'Python-RSA.tex', u'Python-RSA Documentation',
u'Sybren A. Stüvel', 'manual'),
('index', 'Python-RSA.tex', 'Python-RSA Documentation',
'Sybren A. Stüvel', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -213,8 +213,8 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'python-rsa', u'Python-RSA Documentation',
[u'Sybren A. Stüvel'], 1)
('index', 'python-rsa', 'Python-RSA Documentation',
['Sybren A. Stüvel'], 1)
]

todo_include_todos = True
569 changes: 239 additions & 330 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Expand Up @@ -21,6 +21,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
hugovk marked this conversation as resolved.
Show resolved Hide resolved
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Security :: Cryptography",
Expand All @@ -32,7 +33,7 @@ include = [
]

[tool.poetry.dependencies]
python = ">=3.7, <4"
python = ">=3.8, <4"
pyasn1 = ">=0.1.3"

[tool.poetry.dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion rsa/cli.py
Expand Up @@ -178,7 +178,7 @@ def parse_cli(self) -> typing.Tuple[optparse.Values, typing.List[str]]:
def read_key(self, filename: str, keyform: str) -> rsa.key.AbstractKey:
"""Reads a public or private key."""

print("Reading %s key from %s" % (self.keyname, filename), file=sys.stderr)
sybrenstuvel marked this conversation as resolved.
Show resolved Hide resolved
print("Reading {} key from {}".format(self.keyname, filename), file=sys.stderr)
with open(filename, "rb") as keyfile:
keydata = keyfile.read()

Expand Down
2 changes: 1 addition & 1 deletion rsa/core.py
Expand Up @@ -23,7 +23,7 @@ def assert_int(var: int, name: str) -> None:
if isinstance(var, int):
return

raise TypeError("%s should be an integer, not %s" % (name, var.__class__))
raise TypeError("{} should be an integer, not {}".format(name, var.__class__))


def encrypt_int(message: int, ekey: int, n: int) -> int:
Expand Down
2 changes: 1 addition & 1 deletion rsa/key.py
Expand Up @@ -140,7 +140,7 @@ def _assert_format_exists(
except KeyError as ex:
formats = ", ".join(sorted(methods.keys()))
raise ValueError(
"Unsupported format: %r, try one of %s" % (file_format, formats)
"Unsupported format: {!r}, try one of {}".format(file_format, formats)
) from ex

def save_pkcs1(self, format: str = "PEM") -> bytes:
Expand Down
32 changes: 15 additions & 17 deletions rsa/pkcs1.py
Expand Up @@ -60,23 +60,21 @@
"""Hash methods supported by this library."""


if sys.version_info >= (3, 6):
# Python 3.6 introduced SHA3 support.
HASH_ASN1.update(
{
"SHA3-256": b"\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x08\x05\x00\x04\x20",
"SHA3-384": b"\x30\x41\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x09\x05\x00\x04\x30",
"SHA3-512": b"\x30\x51\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x0a\x05\x00\x04\x40",
}
)

HASH_METHODS.update(
{
"SHA3-256": hashlib.sha3_256,
"SHA3-384": hashlib.sha3_384,
"SHA3-512": hashlib.sha3_512,
}
)
HASH_ASN1.update(
hugovk marked this conversation as resolved.
Show resolved Hide resolved
{
"SHA3-256": b"\x30\x31\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x08\x05\x00\x04\x20",
"SHA3-384": b"\x30\x41\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x09\x05\x00\x04\x30",
"SHA3-512": b"\x30\x51\x30\x0d\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x0a\x05\x00\x04\x40",
}
)

HASH_METHODS.update(
{
"SHA3-256": hashlib.sha3_256,
"SHA3-384": hashlib.sha3_384,
"SHA3-512": hashlib.sha3_512,
}
)


class CryptoError(Exception):
Expand Down
4 changes: 2 additions & 2 deletions rsa/util.py
Expand Up @@ -67,7 +67,7 @@ def private_to_public() -> None:
# Read the input data
if cli.infilename:
print(
"Reading private key from %s in %s format" % (cli.infilename, cli.inform),
"Reading private key from {} in {} format".format(cli.infilename, cli.inform),
file=sys.stderr,
)
with open(cli.infilename, "rb") as infile:
Expand All @@ -87,7 +87,7 @@ def private_to_public() -> None:

if cli.outfilename:
print(
"Writing public key to %s in %s format" % (cli.outfilename, cli.outform),
"Writing public key to {} in {} format".format(cli.outfilename, cli.outform),
file=sys.stderr,
)
with open(cli.outfilename, "wb") as outfile:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -9,7 +9,7 @@ max-complexity = 10
max-line-length = 100

[mypy]
python_version = 3.7
python_version = 3.8
warn_unused_ignores = True
ignore_missing_imports = True
follow_imports = skip
Expand Down
1 change: 0 additions & 1 deletion tests/test_cli.py
Expand Up @@ -2,7 +2,6 @@
Unit tests for CLI entry points.
"""

from __future__ import print_function

import functools
import io
Expand Down
3 changes: 1 addition & 2 deletions tests/test_strings.py
Expand Up @@ -14,13 +14,12 @@

"""Tests string operations."""

from __future__ import absolute_import

import unittest

import rsa

unicode_string = u"Euro=\u20ac ABCDEFGHIJKLMNOPQRSTUVWXYZ"
unicode_string = "Euro=\u20ac ABCDEFGHIJKLMNOPQRSTUVWXYZ"


class StringTest(unittest.TestCase):
Expand Down
10 changes: 2 additions & 8 deletions tox.ini
@@ -1,6 +1,6 @@
[tox]
# Environment changes have to be manually synced with '.travis.yml'.
envlist = py37,py38,py39,py310,py311
envlist = py{38,39,310,311,312}
isolated_build = True

[pytest]
Expand All @@ -10,10 +10,4 @@ addopts = -v --cov rsa --cov-report term-missing
deps = poetry
commands =
poetry install
poetry run py.test tests/

[testenv:py37]
whitelist_externals = poetry
commands=
poetry install
poetry run py.test --doctest-modules rsa tests/
poetry run pytest tests/
hugovk marked this conversation as resolved.
Show resolved Hide resolved