Skip to content

Commit e60d258

Browse files
committed
reformat code, add linting CI, bump to 0.3.2, fix README.md
1 parent d5096d7 commit e60d258

File tree

10 files changed

+68
-22
lines changed

10 files changed

+68
-22
lines changed

.github/workflows/lint.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Python application
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-24.04
8+
strategy:
9+
matrix:
10+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
11+
steps:
12+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
13+
- name: Set up Python ${{ matrix.python-version }}
14+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
15+
with:
16+
python-version: ${{ matrix.python-version }}
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install flake8
21+
pip install ./
22+
- name: Check CLI commands
23+
run: |
24+
ksef_auth_file --help
25+
ksef_auth_pkcs11 --help
26+
p11_list_objects --help
27+
p11_list_tokens --help
28+
- name: Lint with flake8
29+
run: |
30+
flake8 src/pyksef --max-line-length=120

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# Python KSeF Authentication Library (for PKCS#11 and local private keys)
22

3-
> [!NOTE]
4-
> PL: Biblioteka do języka Python obsługująca logowanie do KSeF z użyciem dowolnego klucza prywatnego obsługującego interfejs PKCS#11 – kwalifikowane podpisy i pieczęci elektroniczne (na karcie, tokenie USB lub w formie HSM), a także certyfikaty wydane przez KSeF, do których klucze prywatne przechowywane są na HSMie (np. YubiHSM, YubiKey, Google Cloud KMS). Obsługuje również klasyczne uwierzytelnianie kluczem przechowywanym lokalnie na dysku twardym w pliku `.key` (format PEM).
3+
## (PL) Opis
54

6-
Supported features:
5+
Biblioteka do Pythona implementująca logowanie do Krajowego Systemu e-Faktur (KSeF) z użyciem dowolnego klucza prywatnego obsługującego interfejs PKCS#11.
6+
Obsługuje kwalifikowane podpisy i pieczęci elektroniczne w dowolnej postaci (na karcie, tokenie USB lub w formie HSM), a także certyfikaty wydane przez KSeF, do których klucze prywatne przechowywane są na HSMie (np. YubiHSM, YubiKey, Google Cloud KMS). Biblioteka wspiera również klasyczne uwierzytelnianie kluczem przechowywanym lokalnie na dysku twardym w pliku `.key` (format PEM).
7+
8+
9+
## Supported features
710

811
* Authentication using private keys available through PKCS#11 interface:
912
* Qualified signature or qualified seal issued on a physical device,
@@ -293,10 +296,12 @@ ksef_auth_file \
293296

294297
## Troubleshooting
295298

296-
If you see the following exception even though the DLL physically exists at the path indicated:
299+
In case if you see the following exception even though the DLL physically exists at the path indicated:
297300

298301
```
299302
pkcs11.exceptions.PKCS11Error: OS exception while loading <file path>.dll: The specified module could not be found.
300303
```
301304

302-
please check if your `PATH` environment variable is set correctly. Your PKCS#11 DLL might depend on some auxiliary DLLs that are unavailable.
305+
Please check if your `PATH` environment variable is set correctly. The error is actually due to the fact that your PKCS#11 DLL tries to load other DLLs that couldn't be located within the `PATH`.
306+
307+
If your PKCS#11 library comes with other required DLL files that are all hosted within the same directory, it is going to help when you add the directory of your PKCS#11 library to `PATH` environment variable.

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pyksef"
7-
version = "0.3.1"
7+
version = "0.3.2"
88
description = "KSeF Authentication library"
99
readme = "README.md"
1010
authors = [
1111
{name = "Michał Leszczyński", email = "ml@icedev.pl"}
1212
]
1313
license = {text = "MIT"}
14-
requires-python = ">=3.8"
14+
requires-python = ">=3.10"
1515
classifiers = [
1616
"Development Status :: 3 - Alpha",
1717
"Intended Audience :: Developers",
1818
"License :: OSI Approved :: MIT License",
1919
"Programming Language :: Python :: 3",
20-
"Programming Language :: Python :: 3.8",
21-
"Programming Language :: Python :: 3.9",
2220
"Programming Language :: Python :: 3.10",
2321
"Programming Language :: Python :: 3.11",
2422
"Programming Language :: Python :: 3.12",
23+
"Programming Language :: Python :: 3.13",
24+
"Programming Language :: Python :: 3.14",
2525
]
2626
dependencies = [
2727
"requests>=2.32.5",

src/pyksef/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
"""KSeF XAdES Authentication Library"""
1+
"""Python KSeF Authentication Library (for PKCS#11 and local private keys)"""
22

3-
__version__ = "0.3.1"
3+
__version__ = "0.3.2"
44

55
from pyksef.auth import ksef_auth_xades
66

src/pyksef/auth/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from pyksef.auth.xades_auth import ksef_auth_xades
1+
from pyksef.auth.xades_auth import ksef_auth_xades # noqa: F401

src/pyksef/auth/state.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class KSEFAuthFailError(RuntimeError):
1414
def __init__(self, auth_state):
1515
status_code = auth_state["status"]["code"]
1616
auth_state_str = json.dumps(auth_state)
17-
super(KSEFAuthFailError, self).__init__(f"Authentication failed with status code: {status_code}: {auth_state_str}")
17+
super(KSEFAuthFailError, self).__init__(
18+
f"Authentication failed with status code: {status_code}: {auth_state_str}")
1819
self.auth_state = auth_state
1920

2021

@@ -38,8 +39,8 @@ def ksef_poll_auth_finalized(
3839
api_base_url: str,
3940
reference_number: str,
4041
authentication_token: str,
41-
poll_interval: float=1.0,
42-
timeout: float=120.0) -> dict:
42+
poll_interval: float = 1.0,
43+
timeout: float = 120.0) -> dict:
4344
if poll_interval < 0.1:
4445
raise ValueError("Poll interval is smaller than 0.1s")
4546

src/pyksef/auth/xades_auth.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313

1414
def _build_xml(challenge: str, context_id: ContextIdentifier,
1515
subject_id_type: SubjectIdentifierType) -> etree.ElementTree:
16+
root_ns = ('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
17+
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
18+
'xmlns="http://ksef.mf.gov.pl/auth/token/2.0"')
1619
data = f"""<?xml version="1.0" encoding="utf-8"?>
17-
<AuthTokenRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://ksef.mf.gov.pl/auth/token/2.0">
20+
<AuthTokenRequest {root_ns}>
1821
<Challenge>{challenge}</Challenge>
1922
<ContextIdentifier>
2023
{context_id.serialize()}

src/pyksef/cli/ksef_auth_file.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def cli():
4242
help="Optional: 'nip' (default), 'nipVatUe', or 'internalId'.")
4343
parser.add_argument("--context-id", required=True, help="Context identifier to authenticate against.")
4444
parser.add_argument("--subject-id-type", default="certificateSubject",
45-
help="Optional: Subject identifier type: 'certificateSubject' (default) or 'certificateFingerprint'.")
45+
help="Optional: Subject identifier type: 'certificateSubject' (default) "
46+
"or 'certificateFingerprint'.")
4647
args = parser.parse_args()
4748

4849
context_id = ContextIdentifier(

src/pyksef/cli/ksef_auth_pkcs11.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,19 @@ def cli():
4848
parser.add_argument("--key-id", help="Private key ID (hex).")
4949
parser.add_argument("--key-label", help="Private key label.")
5050
parser.add_argument("--user-pin",
51-
help="Optional: User PIN to login to the token. You will be interactively prompted for PIN if this argument is not provided.")
51+
help="Optional: User PIN to login to the token. You will be interactively prompted for "
52+
"PIN if this argument is not provided.")
5253
parser.add_argument("--cert-file",
53-
help="Optional: File path for X.509 PEM Certificate file. If not provided, we will try to load it from the token (device) itself.")
54+
help="Optional: File path for X.509 PEM Certificate file. If not provided, we will try "
55+
"to load it from the token (device) itself.")
5456
parser.add_argument("--api-base-url", default="https://api.ksef.mf.gov.pl/v2",
5557
help="Optional: KSeF API base url. Default: https://api.ksef.mf.gov.pl/v2")
5658
parser.add_argument("--context-id-type", default="nip",
5759
help="Optional: 'nip' (default), 'nipVatUe', or 'internalId'.")
5860
parser.add_argument("--context-id", required=True, help="Context identifier to authenticate against.")
5961
parser.add_argument("--subject-id-type", default="certificateSubject",
60-
help="Optional: Subject identifier type: 'certificateSubject' (default) or 'certificateFingerprint'.")
62+
help="Optional: Subject identifier type: 'certificateSubject' (default) "
63+
"or 'certificateFingerprint'.")
6164
args = parser.parse_args()
6265

6366
context_id = ContextIdentifier(

src/pyksef/cli/p11_list_objects.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ def cli():
3636
parser.add_argument("--token-label", help="Token's label.")
3737
parser.add_argument("--token-serial", help="Token's serial number (hex).")
3838
parser.add_argument("--user-pin",
39-
help="Optional: User PIN to login to the token. You will be interactively prompted for PIN if this argument is not provided.")
39+
help="Optional: User PIN to login to the token. You will be interactively prompted "
40+
"for PIN if this argument is not provided.")
4041
parser.add_argument("--output", choices=["list", "certificates"], default="list",
41-
help="Output type. For 'list' will output a list of certificates and private keys available with certain PKCS#11 token. For 'certificates' it will dump all available certificates in the PEM format.")
42+
help="Output type. For 'list' will output a list of certificates and private keys available "
43+
"with certain PKCS#11 token. For 'certificates' it will dump all available certificates "
44+
"in the PEM format.")
4245
args = parser.parse_args()
4346

4447
token_serial = None

0 commit comments

Comments
 (0)