diff --git a/ChangeLog.rst b/ChangeLog.rst index 92d779b..b6fec81 100644 --- a/ChangeLog.rst +++ b/ChangeLog.rst @@ -1,3 +1,9 @@ +wolfCrypt-py Release NEXT (TBD, 2026) +========================================== + +* Add extra nonce parameter to Random generator + + wolfCrypt-py Release 5.8.4 (Jan 7, 2026) ========================================== diff --git a/requirements/test.txt b/requirements/test.txt index 8c01ca8..53c4efe 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,3 +1,4 @@ -r prod.txt tox pytest +types-cffi diff --git a/setup.py b/setup.py index ed2836e..ba23674 100755 --- a/setup.py +++ b/setup.py @@ -74,6 +74,7 @@ setup( u"Programming Language :: Python :: 3.7", u"Programming Language :: Python :: 3.8", u"Programming Language :: Python :: 3.9", + u"Programming Language :: Python :: 3.10", u"Topic :: Security", u"Topic :: Security :: Cryptography", u"Topic :: Software Development" @@ -83,5 +84,5 @@ setup( install_requires=["cffi>=1.0.0"], cffi_modules=["./scripts/build_ffi.py:ffibuilder"], - package_data={"wolfcrypt": ["*.dll"]} + package_data={"wolfcrypt": ["*.dll", "**/*.pyi"]} ) diff --git a/wolfcrypt/_ffi/__init__.pyi b/wolfcrypt/_ffi/__init__.pyi index fd4cc63..f3a1ba1 100644 --- a/wolfcrypt/_ffi/__init__.pyi +++ b/wolfcrypt/_ffi/__init__.pyi @@ -1,5 +1,5 @@ import _cffi_backend -import _ffi.lib as lib +import wolfcrypt._ffi.lib as lib ffi: _cffi_backend.FFI diff --git a/wolfcrypt/random.py b/wolfcrypt/random.py index 62ed4e4..039c44f 100644 --- a/wolfcrypt/random.py +++ b/wolfcrypt/random.py @@ -34,7 +34,7 @@ class Random: """ def __init__(self, nonce: __builtins__.bytes = b"", device_id: int = _lib.INVALID_DEVID) -> None: - self.native_object = _ffi.new("WC_RNG *") + self.native_object: _lib.RNG | None = _ffi.new("WC_RNG *") ret = _lib.wc_InitRngNonce_ex(self.native_object, nonce, len(nonce), _ffi.NULL, device_id) if ret < 0: # pragma: no cover diff --git a/wolfcrypt/utils.py b/wolfcrypt/utils.py index a1c7d37..5de6363 100644 --- a/wolfcrypt/utils.py +++ b/wolfcrypt/utils.py @@ -27,12 +27,19 @@ from binascii import hexlify as b2h, unhexlify as h2b # noqa: F401 def t2b(string: bytes | bytearray | memoryview | str) -> bytes: """ - Converts text to binary. + Converts text to bytes. Passes through bytes unchanged. Objects of type bytearray or memoryview are converted to bytes. Encodes str to UTF-8 bytes. + + :param string: text to convert to bytes. + :raises TypeError: if string is not one of the supported types. """ - if isinstance(string, (bytes, bytearray, memoryview)): + if isinstance(string, bytes): + return string + if isinstance(string, (bytearray, memoryview)): return bytes(string) - return str(string).encode("utf-8") + if isinstance(string, str): + return str(string).encode("utf-8") + raise TypeError(f"String parameter of wrong type {type(string).__name__}, expected bytes, bytearray, memoryview or str")