Addressed various review comments.

pull/100/head
Robert de Vries 2026-04-20 22:37:07 +02:00
parent 917e2942ea
commit 61c7990be0
6 changed files with 21 additions and 6 deletions

View File

@ -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)
==========================================

View File

@ -1,3 +1,4 @@
-r prod.txt
tox
pytest
types-cffi

View File

@ -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"]}
)

View File

@ -1,5 +1,5 @@
import _cffi_backend
import _ffi.lib as lib
import wolfcrypt._ffi.lib as lib
ffi: _cffi_backend.FFI

View File

@ -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

View File

@ -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")