Skip to content

Commit 59a5ad2

Browse files
committed
Add unit test to check python attributes
Signed-off-by: Iyán Méndez Veiga <[email protected]>
1 parent 4e6dce3 commit 59a5ad2

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

tests/test_kem.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ def test_not_enabled():
6868
raise AssertionError(f"An unexpected exception was raised: {ex}")
6969

7070

71+
def test_python_attributes():
72+
for alg_name in oqs.get_enabled_kem_mechanisms():
73+
with oqs.KeyEncapsulation(alg_name) as kem:
74+
if kem.method_name.decode() != alg_name:
75+
raise AssertionError("Incorrect oqs.KeyEncapsulation.method_name")
76+
if kem.alg_version is None:
77+
raise AssertionError("Undefined oqs.KeyEncapsulation.alg_version")
78+
if not 1 <= kem.claimed_nist_level <= 5:
79+
raise AssertionError("Invalid oqs.KeyEncapsulation.claimed_nist_level")
80+
if kem.length_public_key == 0:
81+
raise AssertionError("Incorrect oqs.KeyEncapsulation.length_public_key")
82+
if kem.length_secret_key == 0:
83+
raise AssertionError("Incorrect oqs.KeyEncapsulation.length_secret_key")
84+
if kem.length_ciphertext == 0:
85+
raise AssertionError("Incorrect oqs.KeyEncapsulation.length_signature")
86+
if kem.length_shared_secret == 0:
87+
raise AssertionError("Incorrect oqs.KeyEncapsulation.length_shared_secret")
88+
89+
7190
if __name__ == "__main__":
7291
try:
7392
import nose2

tests/test_sig.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,23 @@ def test_not_enabled():
115115
raise AssertionError(f"An unexpected exception was raised: {ex}")
116116

117117

118+
def test_python_attributes():
119+
for alg_name in oqs.get_enabled_sig_mechanisms():
120+
with oqs.Signature(alg_name) as sig:
121+
if sig.method_name.decode() != alg_name:
122+
raise AssertionError("Incorrect oqs.Signature.method_name")
123+
if sig.alg_version is None:
124+
raise AssertionError("Undefined oqs.Signature.alg_version")
125+
if not 1 <= sig.claimed_nist_level <= 5:
126+
raise AssertionError("Invalid oqs.Signature.claimed_nist_level")
127+
if sig.length_public_key == 0:
128+
raise AssertionError("Incorrect oqs.Signature.length_public_key")
129+
if sig.length_secret_key == 0:
130+
raise AssertionError("Incorrect oqs.Signature.length_secret_key")
131+
if sig.length_signature == 0:
132+
raise AssertionError("Incorrect oqs.Signature.length_signature")
133+
134+
118135
if __name__ == "__main__":
119136
try:
120137
import nose2

0 commit comments

Comments
 (0)