Skip to content

Commit fbc5367

Browse files
authored
Merge branch 'master' into fix-keytype-for-eddsa-test
2 parents ed14873 + 03db4e5 commit fbc5367

36 files changed

+1325
-943
lines changed

.github/workflows/quality.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Code quality
2+
on:
3+
push:
4+
pull_request:
5+
6+
jobs:
7+
8+
run:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
13+
- name: Acquire sources
14+
uses: actions/[email protected]
15+
16+
- name: Setup Python
17+
uses: actions/[email protected]
18+
with:
19+
python-version: "3.12"
20+
architecture: x64
21+
22+
- name: Apply caching of dependencies
23+
uses: actions/[email protected]
24+
with:
25+
path: ~/.cache/pip
26+
key: pip-${{ hashFiles('**/requirements-*.txt') }}
27+
28+
- name: Install dependencies
29+
run: |
30+
pip install -U pip setuptools wheel
31+
pip install -r requirements.txt -r dev-requirements.txt
32+
33+
- name: Run ruff
34+
run: |
35+
ruff format --diff .
36+
ruff check --diff .

dev-requirements.in

Lines changed: 0 additions & 12 deletions
This file was deleted.

dev-requirements.txt

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,10 @@
1-
#
2-
# This file is autogenerated by pip-compile
3-
# To update, run:
4-
#
5-
# pip-compile dev-requirements.in
6-
#
7-
alabaster==0.7.12 # via sphinx
8-
asn1crypto==1.3.0 # via oscrypto
9-
babel==2.8.0 # via sphinx
10-
certifi==2019.11.28 # via requests
11-
cffi==1.14.0 # via cryptography
12-
chardet==3.0.4 # via requests
13-
cryptography==3.2 # via -r dev-requirements.in
14-
cython==0.29.15 # via -r dev-requirements.in
15-
docutils==0.16 # via sphinx
16-
entrypoints==0.3 # via flake8
17-
flake8==3.7.9 # via -r dev-requirements.in
18-
idna==2.9 # via requests
19-
imagesize==1.2.0 # via sphinx
20-
jinja2==2.11.1 # via sphinx
21-
markupsafe==1.1.1 # via jinja2
22-
mccabe==0.6.1 # via flake8
23-
oscrypto==1.2.0 # via -r dev-requirements.in
24-
packaging==20.1 # via sphinx
25-
parameterized==0.7.4 # via -r dev-requirements.in
26-
pycodestyle==2.5.0 # via flake8
27-
pycparser==2.19 # via cffi
28-
pyflakes==2.1.1 # via flake8
29-
pygments==2.5.2 # via sphinx
30-
pyparsing==2.4.6 # via packaging
31-
pytz==2019.3 # via babel
32-
requests==2.23.0 # via sphinx
33-
setuptools-scm==3.5.0 # via -r dev-requirements.in
34-
six==1.14.0 # via cryptography, packaging
35-
snowballstemmer==2.0.0 # via sphinx
36-
sphinx-rtd-theme==0.4.3 # via -r dev-requirements.in
37-
sphinx==2.4.3 # via -r dev-requirements.in, sphinx-rtd-theme
38-
sphinxcontrib-applehelp==1.0.1 # via sphinx
39-
sphinxcontrib-devhelp==1.0.1 # via sphinx
40-
sphinxcontrib-htmlhelp==1.0.3 # via sphinx
41-
sphinxcontrib-jsmath==1.0.1 # via sphinx
42-
sphinxcontrib-qthelp==1.0.2 # via sphinx
43-
sphinxcontrib-serializinghtml==1.1.3 # via sphinx
44-
urllib3==1.25.8 # via requests
1+
Cython
2+
setuptools_scm
453

46-
# The following packages are considered to be unsafe in a requirements file:
47-
# setuptools
4+
# Used for tests
5+
oscrypto
6+
cryptography
7+
parameterized
8+
ruff==0.8.2
9+
sphinx
10+
sphinx-rtd-theme

docs/conf.py

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
#
2020
import os
2121
import sys
22+
2223
import sphinx_rtd_theme
2324

24-
sys.path.insert(0, os.path.abspath('..'))
25+
sys.path.insert(0, os.path.abspath(".."))
2526

2627

2728
# -- General configuration ------------------------------------------------
@@ -34,40 +35,40 @@
3435
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3536
# ones.
3637
extensions = [
37-
'sphinx.ext.autodoc',
38-
'sphinx.ext.coverage',
39-
'sphinx.ext.intersphinx',
38+
"sphinx.ext.autodoc",
39+
"sphinx.ext.coverage",
40+
"sphinx.ext.intersphinx",
4041
]
4142

42-
autodoc_member_order = 'bysource'
43+
autodoc_member_order = "bysource"
4344

44-
intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}
45+
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}
4546

4647
# Add any paths that contain templates here, relative to this directory.
47-
templates_path = ['_templates']
48+
templates_path = ["_templates"]
4849

4950
# The suffix(es) of source filenames.
5051
# You can specify multiple suffix as a list of string:
5152
#
5253
# source_suffix = ['.rst', '.md']
53-
source_suffix = '.rst'
54+
source_suffix = ".rst"
5455

5556
# The master toctree document.
56-
master_doc = 'index'
57+
master_doc = "index"
5758

5859
# General information about the project.
59-
project = 'Python PKCS#11'
60-
copyright = '2017, Danielle Madeley'
61-
author = 'Danielle Madeley'
60+
project = "Python PKCS#11"
61+
copyright = "2017, Danielle Madeley"
62+
author = "Danielle Madeley"
6263

6364
# The version info for the project you're documenting, acts as replacement for
6465
# |version| and |release|, also used in various other places throughout the
6566
# built documents.
6667
#
6768
# The short X.Y version.
68-
version = ''
69+
version = ""
6970
# The full version, including alpha/beta/rc tags.
70-
release = ''
71+
release = ""
7172

7273
# The language for content autogenerated by Sphinx. Refer to documentation
7374
# for a list of supported languages.
@@ -79,10 +80,10 @@
7980
# List of patterns, relative to source directory, that match files and
8081
# directories to ignore when looking for source files.
8182
# This patterns also effect to html_static_path and html_extra_path
82-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
83+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
8384

8485
# The name of the Pygments (syntax highlighting) style to use.
85-
pygments_style = 'sphinx'
86+
pygments_style = "sphinx"
8687

8788
# If true, `todo` and `todoList` produce output, else they produce nothing.
8889
todo_include_todos = False
@@ -93,7 +94,7 @@
9394
# The theme to use for HTML and HTML Help pages. See the documentation for
9495
# a list of builtin themes.
9596
#
96-
html_theme = 'sphinx_rtd_theme'
97+
html_theme = "sphinx_rtd_theme"
9798
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
9899

99100
# Theme options are theme-specific and customize the look and feel of a theme
@@ -105,13 +106,13 @@
105106
# Add any paths that contain custom static files (such as style sheets) here,
106107
# relative to this directory. They are copied after the builtin static files,
107108
# so a file named "default.css" will overwrite the builtin "default.css".
108-
html_static_path = ['_static']
109+
html_static_path = ["_static"]
109110

110111

111112
# -- Options for HTMLHelp output ------------------------------------------
112113

113114
# Output file base name for HTML help builder.
114-
htmlhelp_basename = 'PythonPKCS11doc'
115+
htmlhelp_basename = "PythonPKCS11doc"
115116

116117

117118
# -- Options for LaTeX output ---------------------------------------------
@@ -120,15 +121,12 @@
120121
# The paper size ('letterpaper' or 'a4paper').
121122
#
122123
# 'papersize': 'letterpaper',
123-
124124
# The font size ('10pt', '11pt' or '12pt').
125125
#
126126
# 'pointsize': '10pt',
127-
128127
# Additional stuff for the LaTeX preamble.
129128
#
130129
# 'preamble': '',
131-
132130
# Latex figure (float) alignment
133131
#
134132
# 'figure_align': 'htbp',
@@ -138,19 +136,21 @@
138136
# (source start file, target name, title,
139137
# author, documentclass [howto, manual, or own class]).
140138
latex_documents = [
141-
(master_doc, 'PythonPKCS11.tex', 'Python PKCS\\#11 Documentation',
142-
'Danielle Madeley', 'manual'),
139+
(
140+
master_doc,
141+
"PythonPKCS11.tex",
142+
"Python PKCS\\#11 Documentation",
143+
"Danielle Madeley",
144+
"manual",
145+
),
143146
]
144147

145148

146149
# -- Options for manual page output ---------------------------------------
147150

148151
# One entry per manual page. List of tuples
149152
# (source start file, name, description, authors, manual section).
150-
man_pages = [
151-
(master_doc, 'pythonpkcs11', 'Python PKCS#11 Documentation',
152-
[author], 1)
153-
]
153+
man_pages = [(master_doc, "pythonpkcs11", "Python PKCS#11 Documentation", [author], 1)]
154154

155155

156156
# -- Options for Texinfo output -------------------------------------------
@@ -159,10 +159,13 @@
159159
# (source start file, target name, title, author,
160160
# dir menu entry, description, category)
161161
texinfo_documents = [
162-
(master_doc, 'PythonPKCS11', 'Python PKCS#11 Documentation',
163-
author, 'PythonPKCS11', 'One line description of project.',
164-
'Miscellaneous'),
162+
(
163+
master_doc,
164+
"PythonPKCS11",
165+
"Python PKCS#11 Documentation",
166+
author,
167+
"PythonPKCS11",
168+
"One line description of project.",
169+
"Miscellaneous",
170+
),
165171
]
166-
167-
168-

docs/opensc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Smartcard-HSM can generate a shared key via ECDH key exchange.
175175

176176
# Bob generates a keypair, with their public key encoded for
177177
# interchange
178-
bob_priv = ec.generate_private_key(ec.SECP256R1,
178+
bob_priv = ec.generate_private_key(ec.SECP256R1(),
179179
default_backend())
180180
bob_pub = bob_priv.public_key().public_bytes(
181181
Encoding.DER,

pkcs11/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
from .exceptions import * # noqa: F403
77
from .mechanisms import * # noqa: F403
88
from .types import * # noqa: F403
9-
9+
from .util import dh # noqa: F403
10+
from .util import dsa # noqa: F403
11+
from .util import ec # noqa: F403
12+
from .util import rsa # noqa: F403
13+
from .util import x509 # noqa: F403
1014

1115
_so = None
1216
_lib = None
@@ -23,7 +27,8 @@ def lib(so):
2327
if _lib:
2428
if _so != so:
2529
raise AlreadyInitialized( # noqa: F405
26-
"Already initialized with %s" % so)
30+
"Already initialized with %s" % so
31+
)
2732
else:
2833
return _lib
2934

pkcs11/_pkcs11.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ class Session(types.Session):
377377
"""Extend Session with implementation."""
378378

379379
def close(self):
380-
cdef CK_OBJECT_HANDLE handle = self._handle
380+
cdef CK_SESSION_HANDLE handle = self._handle
381381

382382
if self.user_type != UserType.NOBODY:
383383
with nogil:

pkcs11/constants.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ObjectClass(IntEnum):
4040
4141
This is the type of object we have.
4242
"""
43+
4344
DATA = 0x00000000
4445
CERTIFICATE = 0x00000001
4546
"""See :class:`pkcs11.Certificate`."""
@@ -58,7 +59,7 @@ class ObjectClass(IntEnum):
5859
_VENDOR_DEFINED = 0x80000000
5960

6061
def __repr__(self):
61-
return '<ObjectClass.%s>' % self.name
62+
return "<ObjectClass.%s>" % self.name
6263

6364

6465
_ARRAY_ATTRIBUTE = 0x40000000
@@ -298,9 +299,9 @@ class Attribute(IntEnum):
298299

299300
WRAP_WITH_TRUSTED = 0x00000210
300301
"""Key can only be wrapped with a `TRUSTED` key."""
301-
WRAP_TEMPLATE = (_ARRAY_ATTRIBUTE | 0x00000211)
302-
UNWRAP_TEMPLATE = (_ARRAY_ATTRIBUTE | 0x00000212)
303-
DERIVE_TEMPLATE = (_ARRAY_ATTRIBUTE | 0x00000213)
302+
WRAP_TEMPLATE = _ARRAY_ATTRIBUTE | 0x00000211
303+
UNWRAP_TEMPLATE = _ARRAY_ATTRIBUTE | 0x00000212
304+
DERIVE_TEMPLATE = _ARRAY_ATTRIBUTE | 0x00000213
304305

305306
OTP_FORMAT = 0x00000220
306307
OTP_LENGTH = 0x00000221
@@ -339,18 +340,19 @@ class Attribute(IntEnum):
339340
REQUIRED_CMS_ATTRIBUTES = 0x00000501
340341
DEFAULT_CMS_ATTRIBUTES = 0x00000502
341342
SUPPORTED_CMS_ATTRIBUTES = 0x00000503
342-
ALLOWED_MECHANISMS = (_ARRAY_ATTRIBUTE | 0x00000600)
343+
ALLOWED_MECHANISMS = _ARRAY_ATTRIBUTE | 0x00000600
343344

344345
_VENDOR_DEFINED = 0x80000000
345346

346347
def __repr__(self):
347-
return '<Attribute.%s>' % self.name
348+
return "<Attribute.%s>" % self.name
348349

349350

350351
class CertificateType(IntEnum):
351352
"""
352353
Certificate type of a :class:`pkcs11.Certificate`.
353354
"""
355+
354356
X_509 = 0x00000000
355357
X_509_ATTR_CERT = 0x00000001
356358
WTLS = 0x00000002
@@ -366,6 +368,7 @@ class MechanismFlag(IntFlag):
366368
Some objects and mechanisms are symmetric (i.e. can be used for encryption
367369
and decryption), some are asymmetric (e.g. public key cryptography).
368370
"""
371+
369372
HW = 0x00000001
370373
"""Mechanism is performed in hardware."""
371374

0 commit comments

Comments
 (0)