From 97766d708b98f6e1e37b053c9ccfa39cd7b4c0b3 Mon Sep 17 00:00:00 2001 From: Robert de Vries Date: Sun, 21 Jun 2026 17:44:52 +0200 Subject: [PATCH] Address more review comments. Also added a line to the change log to mention that typing information has been added. --- ChangeLog.rst | 1 + wolfcrypt/__init__.py | 5 +---- wolfcrypt/ciphers.py | 14 ++++++-------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/ChangeLog.rst b/ChangeLog.rst index 06c5ed8..61eb4a2 100644 --- a/ChangeLog.rst +++ b/ChangeLog.rst @@ -28,6 +28,7 @@ wolfCrypt-py Release 5.9.2 (Jul 1, 2026) * Address many small issues found by Fenrir * Add reseed support to random number generator * The RsaPublic key parameter is now mandatory as it is always needed by an internal function call. +* Add typing annotations wolfCrypt-py Release 5.8.4 (Jan 7, 2026) diff --git a/wolfcrypt/__init__.py b/wolfcrypt/__init__.py index c2514df..4de64b1 100644 --- a/wolfcrypt/__init__.py +++ b/wolfcrypt/__init__.py @@ -17,9 +17,6 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -from typing import cast - -from _cffi_backend import Lib from wolfcrypt._version import __version__, __wolfssl_version__ @@ -53,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(cast(Lib, _lib), "wc_GenerateSeed")) + 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/ciphers.py b/wolfcrypt/ciphers.py index d3bfb07..8690474 100644 --- a/wolfcrypt/ciphers.py +++ b/wolfcrypt/ciphers.py @@ -2397,19 +2397,18 @@ if _lib.ML_DSA_ENABLED: return mldsa_priv @classmethod - def make_key_from_seed(cls, mldsa_type: MlDsaType, seed: bytes | list[int] | tuple[int]) -> MlDsaPrivate: + def make_key_from_seed(cls, mldsa_type: MlDsaType, seed: bytes) -> MlDsaPrivate: """ Deterministically generate the key from a seed. :param mldsa_type: ML-DSA type :type mldsa_type: MlDsaType :param seed: the (32 byte) seed from which to deterministically create the key - :type seed: bytes or list/tuple of int (value in the range 0-255) + :type seed: bytes """ mldsa_priv = cls(mldsa_type) - if not isinstance(seed, (list, tuple, bytes)): - raise TypeError("seed must be bytes or list/tuple") + seed = bytes(seed) if len(seed) != cls.ML_DSA_KEYGEN_SEED_LENGTH: raise ValueError( @@ -2549,12 +2548,12 @@ if _lib.ML_DSA_ENABLED: return _ffi.buffer(signature, out_size[0])[:] - def sign_with_seed(self, message: BytesOrStr, seed: bytes | list[int] | tuple[int], ctx: BytesOrStr | None = None) -> bytes: + def sign_with_seed(self, message: BytesOrStr, seed: bytes, ctx: BytesOrStr | None = None) -> bytes: """ :param message: message to be signed :type message: bytes or str :param seed: 32-byte seed for deterministic signature generation. - :type seed: bytes or list/tuple of int (value in the range 0-255) + :type seed: bytes :param ctx: context, maximum 255 bytes (optional by default but that requires support for no-context signing/verification compiled in; pass empty string "" for FIPS-204 empty-context signing). :type ctx: bytes or str. None for no-context signing. @@ -2570,8 +2569,7 @@ if _lib.ML_DSA_ENABLED: out_size = _ffi.new("word32 *") out_size[0] = in_size - if not isinstance(seed, (list, tuple, bytes)): - raise TypeError("seed must be bytes or list/tuple") + seed = bytes(seed) if len(seed) != ML_DSA_SIGNATURE_SEED_LENGTH: raise ValueError(