Skip to content

Commit 6a164a6

Browse files
committed
update
Signed-off-by: Vlad Gheorghiu <[email protected]>
1 parent dc9a597 commit 6a164a6

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

oqs/oqs.py

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,10 @@ def generate_keypair(self):
266266
rv = native().OQS_KEM_keypair(
267267
self._kem, ct.byref(public_key), ct.byref(self.secret_key)
268268
)
269-
return (
270-
bytes(public_key)
271-
if rv == OQS_SUCCESS
272-
else RuntimeError("Can not generate keypair")
273-
)
269+
if rv == OQS_SUCCESS:
270+
return bytes(public_key)
271+
else:
272+
raise RuntimeError("Can not generate keypair")
274273

275274
def export_secret_key(self):
276275
"""Exports the secret key."""
@@ -290,11 +289,10 @@ def encap_secret(self, public_key):
290289
rv = native().OQS_KEM_encaps(
291290
self._kem, ct.byref(ciphertext), ct.byref(shared_secret), c_public_key
292291
)
293-
return bytes(ciphertext), (
294-
bytes(shared_secret)
295-
if rv == OQS_SUCCESS
296-
else RuntimeError("Can not encapsulate secret")
297-
)
292+
if rv == OQS_SUCCESS:
293+
return bytes(ciphertext), bytes(shared_secret)
294+
else:
295+
raise RuntimeError("Can not encapsulate secret")
298296

299297
def decap_secret(self, ciphertext):
300298
"""
@@ -309,11 +307,10 @@ def decap_secret(self, ciphertext):
309307
rv = native().OQS_KEM_decaps(
310308
self._kem, ct.byref(shared_secret), c_ciphertext, self.secret_key
311309
)
312-
return (
313-
bytes(shared_secret)
314-
if rv == OQS_SUCCESS
315-
else RuntimeError("Can not decapsulate secret")
316-
)
310+
if rv == OQS_SUCCESS:
311+
return bytes(shared_secret)
312+
else:
313+
raise RuntimeError("Can not decapsulate secret")
317314

318315
def free(self):
319316
"""Releases the native resources."""
@@ -435,11 +432,10 @@ def generate_keypair(self):
435432
rv = native().OQS_SIG_keypair(
436433
self._sig, ct.byref(public_key), ct.byref(self.secret_key)
437434
)
438-
return (
439-
bytes(public_key)
440-
if rv == OQS_SUCCESS
441-
else RuntimeError("Can not generate keypair")
442-
)
435+
if rv == OQS_SUCCESS:
436+
return bytes(public_key)
437+
else:
438+
raise RuntimeError("Can not generate keypair")
443439

444440
def export_secret_key(self):
445441
"""Exports the secret key."""
@@ -467,11 +463,10 @@ def sign(self, message):
467463
message_len,
468464
self.secret_key,
469465
)
470-
return (
471-
bytes(c_signature[: signature_len.value])
472-
if rv == OQS_SUCCESS
473-
else RuntimeError("Can not sign message")
474-
)
466+
if rv == OQS_SUCCESS:
467+
return bytes(c_signature[: signature_len.value])
468+
else:
469+
raise RuntimeError("Can not sign message")
475470

476471
def verify(self, message, signature, public_key):
477472
"""
@@ -527,11 +522,10 @@ def sign_with_ctx_str(self, message, context):
527522
context_len,
528523
self.secret_key,
529524
)
530-
return (
531-
bytes(c_signature[: signature_len.value])
532-
if rv == OQS_SUCCESS
533-
else RuntimeError("Can not sign message with context string")
534-
)
525+
if rv == OQS_SUCCESS:
526+
return bytes(c_signature[: signature_len.value])
527+
else:
528+
raise RuntimeError("Can not sign message with context string")
535529

536530
def verify_with_ctx_str(self, message, signature, context, public_key):
537531
"""

0 commit comments

Comments
 (0)