@@ -266,7 +266,11 @@ def generate_keypair(self):
266
266
rv = native ().OQS_KEM_keypair (
267
267
self ._kem , ct .byref (public_key ), ct .byref (self .secret_key )
268
268
)
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
+ )
270
274
271
275
def export_secret_key (self ):
272
276
"""Exports the secret key."""
@@ -286,7 +290,11 @@ def encap_secret(self, public_key):
286
290
rv = native ().OQS_KEM_encaps (
287
291
self ._kem , ct .byref (ciphertext ), ct .byref (shared_secret ), c_public_key
288
292
)
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
+ )
290
298
291
299
def decap_secret (self , ciphertext ):
292
300
"""
@@ -301,7 +309,11 @@ def decap_secret(self, ciphertext):
301
309
rv = native ().OQS_KEM_decaps (
302
310
self ._kem , ct .byref (shared_secret ), c_ciphertext , self .secret_key
303
311
)
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
+ )
305
317
306
318
def free (self ):
307
319
"""Releases the native resources."""
@@ -423,7 +435,11 @@ def generate_keypair(self):
423
435
rv = native ().OQS_SIG_keypair (
424
436
self ._sig , ct .byref (public_key ), ct .byref (self .secret_key )
425
437
)
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
+ )
427
443
428
444
def export_secret_key (self ):
429
445
"""Exports the secret key."""
@@ -451,8 +467,11 @@ def sign(self, message):
451
467
message_len ,
452
468
self .secret_key ,
453
469
)
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
+ )
456
475
457
476
def verify (self , message , signature , public_key ):
458
477
"""
@@ -479,7 +498,6 @@ def verify(self, message, signature, public_key):
479
498
signature_len ,
480
499
c_public_key ,
481
500
)
482
-
483
501
return True if rv == OQS_SUCCESS else False
484
502
485
503
def sign_with_ctx_str (self , message , context ):
@@ -509,8 +527,11 @@ def sign_with_ctx_str(self, message, context):
509
527
context_len ,
510
528
self .secret_key ,
511
529
)
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
+ )
514
535
515
536
def verify_with_ctx_str (self , message , signature , context , public_key ):
516
537
"""
@@ -542,7 +563,6 @@ def verify_with_ctx_str(self, message, signature, context, public_key):
542
563
context_len ,
543
564
c_public_key ,
544
565
)
545
-
546
566
return True if rv == OQS_SUCCESS else False
547
567
548
568
def free (self ):
0 commit comments