From 7f82b412e3c7ab8c8a2a2cc00edbca03e7968129 Mon Sep 17 00:00:00 2001 From: Robert de Vries Date: Mon, 22 Jun 2026 22:58:19 +0200 Subject: [PATCH] Address more review comments. --- pyproject.toml | 2 +- wolfcrypt/__init__.py | 2 +- wolfcrypt/asn.py | 2 +- wolfcrypt/ciphers.py | 20 +++++++++++++------- wolfcrypt/{types.py => wc_types.py} | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) rename wolfcrypt/{types.py => wc_types.py} (98%) diff --git a/pyproject.toml b/pyproject.toml index d13041e..1dedc80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ classifiers = [ dynamic = ["version"] dependencies = [ "cffi>=1.17", - "typing-extensions", + "typing-extensions>=4.4.0", ] [project.urls] diff --git a/wolfcrypt/__init__.py b/wolfcrypt/__init__.py index 4de64b1..5960e7a 100644 --- a/wolfcrypt/__init__.py +++ b/wolfcrypt/__init__.py @@ -50,7 +50,7 @@ if top_level_py not in ["setup.py", "build_ffi.py"]: if hasattr(_lib, 'WC_RNG_SEED_CB_ENABLED'): if _lib.WC_RNG_SEED_CB_ENABLED: - ret = _lib.wc_SetSeed_Cb(_ffi.addressof(_lib, "wc_GenerateSeed")) # ty:ignore[no-matching-overload] + ret = _lib.wc_SetSeed_Cb(_ffi.addressof(_lib, "wc_GenerateSeed")) # ty: ignore[no-matching-overload] if ret < 0: raise WolfCryptApiError("wc_SetSeed_Cb failed", ret) if _lib.FIPS_ENABLED and _lib.FIPS_VERSION >= 5: diff --git a/wolfcrypt/asn.py b/wolfcrypt/asn.py index 988716f..36115a8 100644 --- a/wolfcrypt/asn.py +++ b/wolfcrypt/asn.py @@ -28,7 +28,7 @@ from wolfcrypt._ffi import ffi as _ffi from wolfcrypt._ffi import lib as _lib from wolfcrypt.exceptions import WolfCryptError, WolfCryptApiError from wolfcrypt.hashes import _Hash -from .types import SupportsRsaSign, SupportsRsaVerify +from .wc_types import SupportsRsaSign, SupportsRsaVerify if _lib.SHA_ENABLED: from wolfcrypt.hashes import Sha # ty: ignore[possibly-missing-import] diff --git a/wolfcrypt/ciphers.py b/wolfcrypt/ciphers.py index 8690474..d09e2ab 100644 --- a/wolfcrypt/ciphers.py +++ b/wolfcrypt/ciphers.py @@ -33,7 +33,7 @@ from wolfcrypt.exceptions import WolfCryptError, WolfCryptApiError from wolfcrypt.hashes import hash_type_to_cls from wolfcrypt.random import Random from wolfcrypt.utils import BytesOrStr, t2b -from .types import SupportsRsaSign, SupportsRsaVerify +from .wc_types import SupportsRsaSign, SupportsRsaVerify if _lib.ASN_ENABLED: from wolfcrypt.asn import pem_to_der # ty: ignore[possibly-missing-import] @@ -2408,12 +2408,15 @@ if _lib.ML_DSA_ENABLED: """ mldsa_priv = cls(mldsa_type) + try: + memoryview(seed) + except TypeError as exception: + raise TypeError("seed must support the buffer protocol, such as `bytes` or `bytearray`") from exception + seed = bytes(seed) if len(seed) != cls.ML_DSA_KEYGEN_SEED_LENGTH: - raise ValueError( - f"Seed for generating ML-DSA key must be {cls.ML_DSA_KEYGEN_SEED_LENGTH} bytes" - ) + raise ValueError(f"Seed for generating ML-DSA key must be {cls.ML_DSA_KEYGEN_SEED_LENGTH} bytes") ret = _lib.wc_dilithium_make_key_from_seed(mldsa_priv.native_object, seed) @@ -2569,12 +2572,15 @@ if _lib.ML_DSA_ENABLED: out_size = _ffi.new("word32 *") out_size[0] = in_size + try: + memoryview(seed) + except TypeError as exception: + raise TypeError("seed must support the buffer protocol, such as `bytes` or `bytearray`") from exception + seed = bytes(seed) if len(seed) != ML_DSA_SIGNATURE_SEED_LENGTH: - raise ValueError( - f"Seed for generating a signature must be {ML_DSA_SIGNATURE_SEED_LENGTH} bytes." - ) + raise ValueError(f"Seed for generating a signature must be {ML_DSA_SIGNATURE_SEED_LENGTH} bytes.") if ctx is not None: ctx_bytestype = t2b(ctx) diff --git a/wolfcrypt/types.py b/wolfcrypt/wc_types.py similarity index 98% rename from wolfcrypt/types.py rename to wolfcrypt/wc_types.py index 116147c..e5794bf 100644 --- a/wolfcrypt/types.py +++ b/wolfcrypt/wc_types.py @@ -1,4 +1,4 @@ -# types.py +# wc_types.py # # Copyright (C) 2026 wolfSSL Inc. #