Fixed a few type annotations and added bad type tests.
Also added one note to the ChangeLog.pull/125/head
parent
397725336e
commit
1a2829a4cd
|
|
@ -28,7 +28,8 @@ 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
|
||||
* The `native_object` attribute of `Random` is now read-only.
|
||||
* Add typing annotations.
|
||||
|
||||
|
||||
wolfCrypt-py Release 5.8.4 (Jan 7, 2026)
|
||||
|
|
|
|||
|
|
@ -226,6 +226,14 @@ if _lib.ML_DSA_ENABLED:
|
|||
signature_from_same_seed = mldsa_priv.sign_with_seed(message, signature_seed, ctx=context)
|
||||
assert signature == signature_from_same_seed
|
||||
|
||||
@pytest.mark.parametrize("seed", [0, "seed"])
|
||||
def test_sign_with_seed_bad_type(mldsa_type, rng, seed: int | str):
|
||||
mldsa_priv = MlDsaPrivate.make_key(mldsa_type, rng)
|
||||
message = b"This is a test message for ML-DSA signature"
|
||||
context = b"Some context for the signature"
|
||||
with pytest.raises(TypeError):
|
||||
mldsa_priv.sign_with_seed(message, seed, ctx=context)
|
||||
|
||||
def test_make_key_from_seed(mldsa_type):
|
||||
seed = bytes(MlDsaPrivate.ML_DSA_KEYGEN_SEED_LENGTH)
|
||||
assert MlDsaPrivate.make_key_from_seed(mldsa_type, seed)
|
||||
|
|
@ -237,3 +245,8 @@ if _lib.ML_DSA_ENABLED:
|
|||
seed = bytes(seed_length)
|
||||
with pytest.raises(ValueError):
|
||||
MlDsaPrivate.make_key_from_seed(mldsa_type, seed)
|
||||
|
||||
@pytest.mark.parametrize("seed", [0, "seed"])
|
||||
def test_make_key_from_seed_bad_type(mldsa_type, seed: int | str):
|
||||
with pytest.raises(TypeError):
|
||||
MlDsaPrivate.make_key_from_seed(mldsa_type, seed)
|
||||
|
|
|
|||
|
|
@ -617,6 +617,21 @@ if _lib.ML_KEM_ENABLED:
|
|||
ss_recv = mlkem_priv.decapsulate(ct)
|
||||
assert ss_send == ss_recv
|
||||
|
||||
@pytest.mark.parametrize("mlkem_type", mlkem_types)
|
||||
@pytest.mark.parametrize("rand", [0, "rand"])
|
||||
def test_make_key_with_random_bad_random_type(mlkem_type, rand: int | str):
|
||||
with pytest.raises(TypeError):
|
||||
MlKemPrivate.make_key_with_random(mlkem_type, rand)
|
||||
|
||||
@pytest.mark.parametrize("mlkem_type", mlkem_types)
|
||||
@pytest.mark.parametrize("rand", [0, "rand"])
|
||||
def test_encapsulate_with_random_bad_random_type(mlkem_type, rand: int | str):
|
||||
mlkem_pub = MlKemPublic(mlkem_type)
|
||||
assert type(mlkem_pub) is MlKemPublic
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
mlkem_pub.encapsulate_with_random(rand)
|
||||
|
||||
@pytest.mark.parametrize("mlkem_type", mlkem_types)
|
||||
def test_size_properties(mlkem_type):
|
||||
refvals = {
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ class _Cipher(ABC):
|
|||
|
||||
@property
|
||||
@abstractmethod
|
||||
def key_size(self) -> int: ...
|
||||
def key_size(self) -> int | None: ...
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
|
|
@ -2148,6 +2148,14 @@ if _lib.ML_KEM_ENABLED:
|
|||
:rtype: MlKemPrivate
|
||||
"""
|
||||
mlkem_priv = cls(mlkem_type)
|
||||
|
||||
try:
|
||||
memoryview(rand)
|
||||
except TypeError as exception:
|
||||
raise TypeError("rand must support the buffer protocol, such as `bytes` or `bytearray`") from exception
|
||||
|
||||
rand = bytes(rand)
|
||||
|
||||
ret = _lib.wc_KyberKey_MakeKeyWithRandom(mlkem_priv.native_object, rand, len(rand))
|
||||
|
||||
if ret < 0: # pragma: no cover
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class _Hash(ABC):
|
|||
|
||||
@property
|
||||
@abstractmethod
|
||||
def digest_size(self) -> int: ...
|
||||
def digest_size(self) -> int | None: ...
|
||||
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
|
|
|
|||
Loading…
Reference in New Issue