From 1b3f474439c6f0c1a0a7e0b034df1a955f167101 Mon Sep 17 00:00:00 2001 From: Robert de Vries Date: Sun, 21 Jun 2026 21:32:16 +0200 Subject: [PATCH 1/2] Enable more ruff rules requiring only minor or no fixes. Extra rules: All E pycodestyle error rules C4 flake8-comprehensions DTZ flake8-datetimez EXE flake8-executable FA flake8-future-annotations INT flake8-gettext ISC flake8-implicit-str-concat ICN flake8-import-conventions LOG flake8-logging G flake8-logging-format RSE flake8-raise SLOT flake8-slots TID flake8-tidy-imports TC flake8-type-checking FLY flynt PERF Perflint W pycodestyle warnings FURB refurb Ignore E501: line too long --- pyproject.toml | 4 ++-- setup.py | 4 ++-- tests/test_hashes.py | 22 +++++++++++----------- tests/test_mldsa.py | 2 +- wolfcrypt/ciphers.py | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 24606f3..58939a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -99,8 +99,8 @@ target-version = "py310" # Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. # Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or # McCabe complexity (`C901`) by default. -select = ["E4", "E7", "E9", "F", "B", "UP"] -ignore = ["UP031", "UP025", "UP032"] +select = ["E", "F", "B", "UP", "C4", "DTZ", "EXE", "FA", "INT", "ISC", "ICN", "LOG", "G", "RSE", "SLOT", "TID", "TC", "FLY", "PERF", "W", "FURB"] +ignore = ["E501"] # Allow fix for all enabled rules (when `--fix`) is provided. fixable = ["ALL"] diff --git a/setup.py b/setup.py index 9682610..b4d38db 100755 --- a/setup.py +++ b/setup.py @@ -30,13 +30,13 @@ VERSIONFILE = "wolfcrypt/_version.py" verstrline = open(VERSIONFILE).read() VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]" -mo = re.search(VSRE, verstrline, re.M) +mo = re.search(VSRE, verstrline, re.MULTILINE) if mo: verstr = mo.group(1) else: raise RuntimeError(f"Unable to find version string in {VERSIONFILE}.") VSRE = r"^__wolfssl_version__ = ['\"]([^'\"]*)['\"]" -mo = re.search(VSRE, verstrline, re.M) +mo = re.search(VSRE, verstrline, re.MULTILINE) if mo: wolfverstr = mo.group(1) else: diff --git a/tests/test_hashes.py b/tests/test_hashes.py index 3fcf78d..fb9da80 100644 --- a/tests/test_hashes.py +++ b/tests/test_hashes.py @@ -66,27 +66,27 @@ def vectors(): if _lib.SHA256_ENABLED: vectorArray[Sha256]=TestVector( - digest=t2b("96e02e7b1cbcd6f104fe1fdb4652027a" + + digest=t2b("96e02e7b1cbcd6f104fe1fdb4652027a" "5505b68652b70095c6318f9dce0d1844") ) if _lib.SHA384_ENABLED: vectorArray[Sha384]=TestVector( - digest=t2b("4c79d80531203a16f91bee325f18c6aada47f9382fe44fc1" + + digest=t2b("4c79d80531203a16f91bee325f18c6aada47f9382fe44fc1" "1f92917837e9b7902f5dccb7d3656f667a1dce3460bc884b") ) if _lib.SHA512_ENABLED: vectorArray[Sha512]=TestVector( - digest=t2b("88fcf67ffd8558d713f9cedcd852db47" + - "9e6573f0bd9955610a993f609637553c" + - "e8fff55e644ee8a106aae19c07f91b3f" + + digest=t2b("88fcf67ffd8558d713f9cedcd852db47" + "9e6573f0bd9955610a993f609637553c" + "e8fff55e644ee8a106aae19c07f91b3f" "2a2a6d40dfa7302c0fa6a1a9a5bfa03f") ) if _lib.SHA3_ENABLED: vectorArray[Sha3]=TestVector( - digest=t2b("6170dedf06f83c3305ec18b7558384a5" + - "a62d86e42c143d416aaec32f971986c1" + + digest=t2b("6170dedf06f83c3305ec18b7558384a5" + "a62d86e42c143d416aaec32f971986c1" "e84edf61df308cc6d8c310d1956e1908") ) if _lib.HMAC_ENABLED: @@ -96,18 +96,18 @@ def vectors(): ) if _lib.SHA256_ENABLED: vectorArray[HmacSha256]=TestVector( - digest=t2b("9041ac8c66fc350a1a0d5f4fff9d8ef74721d5a43ec8893a2" + + digest=t2b("9041ac8c66fc350a1a0d5f4fff9d8ef74721d5a43ec8893a2" "875cf69576c45c2") ) if _lib.SHA384_ENABLED: vectorArray[HmacSha384]=TestVector( - digest=t2b("f8c589ddf5489404f85c3c718a8345f207fb1ed6c6f5ecb09" + + digest=t2b("f8c589ddf5489404f85c3c718a8345f207fb1ed6c6f5ecb09" "8e8be8aeb1aaa9f0c6dd84c141410b29a47a1a2b3a85ae0") ) if _lib.SHA512_ENABLED: vectorArray[HmacSha512]=TestVector( - digest=t2b("7708a12ca110cd81a334bd4e8bddc4314acd3ed218bbff7c6" + - "486e149fc145e9f5c05f05e919f7c2bc027266e986679984c" + + digest=t2b("7708a12ca110cd81a334bd4e8bddc4314acd3ed218bbff7c6" + "486e149fc145e9f5c05f05e919f7c2bc027266e986679984c" "3ade1a14084ad7627a65c3671a2d05") ) diff --git a/tests/test_mldsa.py b/tests/test_mldsa.py index 023b734..ec06e95 100644 --- a/tests/test_mldsa.py +++ b/tests/test_mldsa.py @@ -133,7 +133,7 @@ def test_sign_verify(mldsa_type, rng): # Verify with wrong message wrong_message = b"This is a wrong message for ML-DSA signature" assert not mldsa_pub.verify(signature, wrong_message) - + # Verify a signature generated without a context but where a context # is provided during verify ctx = b"This is a test context for ML-DSA signature" diff --git a/wolfcrypt/ciphers.py b/wolfcrypt/ciphers.py index 562aabd..5692d19 100644 --- a/wolfcrypt/ciphers.py +++ b/wolfcrypt/ciphers.py @@ -2279,7 +2279,7 @@ def verify(self, signature, message, ctx=None): return res[0] == 1 class MlDsaPrivate(_MlDsaBase): - + @classmethod def make_key(cls, mldsa_type, rng=None): """ @@ -2451,7 +2451,7 @@ def sign(self, message, rng=None, ctx=None): ) if ret < 0: # pragma: no cover raise WolfCryptApiError("wc_dilithium_sign_msg() error", ret) - + if in_size != out_size[0]: raise WolfCryptError(f"{in_size=} and {out_size[0]=} don't match") From ca9412bd3c30f1cf7d75b7e731dc8b88cba09f76 Mon Sep 17 00:00:00 2001 From: Robert de Vries Date: Mon, 22 Jun 2026 23:02:24 +0200 Subject: [PATCH 2/2] Remove obsolete boiler plate comment from the ruff example configuration. --- pyproject.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 58939a0..028fa17 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,9 +96,6 @@ indent-width = 4 target-version = "py310" [tool.ruff.lint] -# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. -# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or -# McCabe complexity (`C901`) by default. select = ["E", "F", "B", "UP", "C4", "DTZ", "EXE", "FA", "INT", "ISC", "ICN", "LOG", "G", "RSE", "SLOT", "TID", "TC", "FLY", "PERF", "W", "FURB"] ignore = ["E501"]