@@ -266,7 +266,11 @@ 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 bytes (public_key ) if rv == OQS_SUCCESS else 0
269+ return (
270+ bytes (public_key )
271+ if rv == OQS_SUCCESS
272+ else RuntimeError ("Can not generate keypair" )
273+ )
270274
271275 def export_secret_key (self ):
272276 """Exports the secret key."""
@@ -286,7 +290,11 @@ def encap_secret(self, public_key):
286290 rv = native ().OQS_KEM_encaps (
287291 self ._kem , ct .byref (ciphertext ), ct .byref (shared_secret ), c_public_key
288292 )
289- return bytes (ciphertext ), bytes (shared_secret ) if rv == OQS_SUCCESS else 0
293+ return bytes (ciphertext ), (
294+ bytes (shared_secret )
295+ if rv == OQS_SUCCESS
296+ else RuntimeError ("Can not encapsulate secret" )
297+ )
290298
291299 def decap_secret (self , ciphertext ):
292300 """
@@ -301,7 +309,11 @@ def decap_secret(self, ciphertext):
301309 rv = native ().OQS_KEM_decaps (
302310 self ._kem , ct .byref (shared_secret ), c_ciphertext , self .secret_key
303311 )
304- return bytes (shared_secret ) if rv == OQS_SUCCESS else 0
312+ return (
313+ bytes (shared_secret )
314+ if rv == OQS_SUCCESS
315+ else RuntimeError ("Can not decapsulate secret" )
316+ )
305317
306318 def free (self ):
307319 """Releases the native resources."""
@@ -423,7 +435,11 @@ def generate_keypair(self):
423435 rv = native ().OQS_SIG_keypair (
424436 self ._sig , ct .byref (public_key ), ct .byref (self .secret_key )
425437 )
426- return bytes (public_key ) if rv == OQS_SUCCESS else 0
438+ return (
439+ bytes (public_key )
440+ if rv == OQS_SUCCESS
441+ else RuntimeError ("Can not generate keypair" )
442+ )
427443
428444 def export_secret_key (self ):
429445 """Exports the secret key."""
@@ -451,8 +467,11 @@ def sign(self, message):
451467 message_len ,
452468 self .secret_key ,
453469 )
454-
455- return bytes (c_signature [: signature_len .value ]) if rv == OQS_SUCCESS else 0
470+ return (
471+ bytes (c_signature [: signature_len .value ])
472+ if rv == OQS_SUCCESS
473+ else RuntimeError ("Can not sign message" )
474+ )
456475
457476 def verify (self , message , signature , public_key ):
458477 """
@@ -479,7 +498,6 @@ def verify(self, message, signature, public_key):
479498 signature_len ,
480499 c_public_key ,
481500 )
482-
483501 return True if rv == OQS_SUCCESS else False
484502
485503 def sign_with_ctx_str (self , message , context ):
@@ -509,8 +527,11 @@ def sign_with_ctx_str(self, message, context):
509527 context_len ,
510528 self .secret_key ,
511529 )
512-
513- return bytes (c_signature [: signature_len .value ]) if rv == OQS_SUCCESS else 0
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+ )
514535
515536 def verify_with_ctx_str (self , message , signature , context , public_key ):
516537 """
@@ -542,7 +563,6 @@ def verify_with_ctx_str(self, message, signature, context, public_key):
542563 context_len ,
543564 c_public_key ,
544565 )
545-
546566 return True if rv == OQS_SUCCESS else False
547567
548568 def free (self ):
0 commit comments