Skip to content

Commit 014d7c2

Browse files
committed
Populate attributes in Python Signature
ctypes.Structure.__init__() initializes Signature attributes using the list _fields_. However, these are empty because this happens before native().OQS_SIG_new() is called. The dict self.details was showing correct values by reading and decoding directly from self._sig. However, all the other public attributes like self.method_name, self.alg_version or the keys and signature lengths were incorrect. Either None or 0 depending on the ctype defined in _fields_. Instead, let's manually populate all relevant attributes from _fields_ after OQS_SIG_new() is called, and let's use those values to create the dict self.details. Signed-off-by: Iyán Méndez Veiga <[email protected]>
1 parent 9e64e12 commit 014d7c2

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

oqs/oqs.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -412,15 +412,25 @@ def __init__(self, alg_name, secret_key=None):
412412
raise MechanismNotSupportedError(alg_name)
413413

414414
self._sig = native().OQS_SIG_new(ct.create_string_buffer(alg_name.encode()))
415+
416+
self.method_name = self._sig.contents.method_name
417+
self.alg_version = self._sig.contents.alg_version
418+
self.claimed_nist_level = self._sig.contents.claimed_nist_level
419+
self.euf_cma = self._sig.contents.euf_cma
420+
self.sig_with_ctx_support = self._sig.contents.sig_with_ctx_support
421+
self.length_public_key = self._sig.contents.length_public_key
422+
self.length_secret_key = self._sig.contents.length_secret_key
423+
self.length_signature = self._sig.contents.length_signature
424+
415425
self.details = {
416-
"name": self._sig.contents.method_name.decode(),
417-
"version": self._sig.contents.alg_version.decode(),
418-
"claimed_nist_level": int(self._sig.contents.claimed_nist_level),
419-
"is_euf_cma": bool(self._sig.contents.euf_cma),
420-
"sig_with_ctx_support": bool(self._sig.contents.sig_with_ctx_support),
421-
"length_public_key": int(self._sig.contents.length_public_key),
422-
"length_secret_key": int(self._sig.contents.length_secret_key),
423-
"length_signature": int(self._sig.contents.length_signature),
426+
"name": self.method_name.decode(),
427+
"version": self.alg_version.decode(),
428+
"claimed_nist_level": int(self.claimed_nist_level),
429+
"is_euf_cma": bool(self.euf_cma),
430+
"sig_with_ctx_support": bool(self.sig_with_ctx_support),
431+
"length_public_key": int(self.length_public_key),
432+
"length_secret_key": int(self.length_secret_key),
433+
"length_signature": int(self.length_signature),
424434
}
425435

426436
if secret_key:

0 commit comments

Comments
 (0)