Wrap _delete/_copy class attrs in staticmethod so self isn't bound as an extra arg.

Fixes #108.
pull/109/head
Kareem 2026-04-22 16:19:41 -07:00
parent ec8ce54e1f
commit f6c27bf55d
3 changed files with 15 additions and 15 deletions

View File

@ -397,7 +397,7 @@ if _lib.AESGCM_STREAM_ENABLED:
_key_sizes = [16, 24, 32]
_native_type = "Aes *"
# making sure _lib.wc_AesFree outlives Aes instances
_delete = _lib.wc_AesFree
_delete = staticmethod(_lib.wc_AesFree)
def __init__(self, key, IV, tag_bytes=16):
"""
@ -698,7 +698,7 @@ if _lib.RSA_ENABLED:
raise WolfCryptError("Key initialization error (%d)" % ret)
# making sure _lib.wc_FreeRsaKey outlives RsaKey instances
_delete = _lib.wc_FreeRsaKey
_delete = staticmethod(_lib.wc_FreeRsaKey)
def __del__(self):
if self.native_object:
@ -1057,7 +1057,7 @@ if _lib.ECC_ENABLED:
raise WolfCryptError("Invalid key error (%d)" % ret)
# making sure _lib.wc_ecc_free outlives ecc_key instances
_delete = _lib.wc_ecc_free
_delete = staticmethod(_lib.wc_ecc_free)
def __del__(self):
if self.native_object:
@ -1423,7 +1423,7 @@ if _lib.ED25519_ENABLED:
raise WolfCryptError("Invalid key error (%d)" % ret)
# making sure _lib.wc_ed25519_free outlives ed25519_key instances
_delete = _lib.wc_ed25519_free
_delete = staticmethod(_lib.wc_ed25519_free)
def __del__(self):
if self.native_object:
@ -1623,7 +1623,7 @@ if _lib.ED448_ENABLED:
raise WolfCryptError("Invalid key error (%d)" % ret)
# making sure _lib.wc_ed448_free outlives ed448_key instances
_delete = _lib.wc_ed448_free
_delete = staticmethod(_lib.wc_ed448_free)
def __del__(self):
if self.native_object:

View File

@ -157,8 +157,8 @@ if _lib.SHA_ENABLED:
digest_size = 20
_native_type = "wc_Sha *"
_native_size = _ffi.sizeof("wc_Sha")
_delete = _lib.wc_ShaFree
_copy = _lib.wc_ShaCopy
_delete = staticmethod(_lib.wc_ShaFree)
_copy = staticmethod(_lib.wc_ShaCopy)
def __del__(self):
if hasattr(self, '_native_object') and not getattr(self, '_shallow_copy', False):
@ -185,8 +185,8 @@ if _lib.SHA256_ENABLED:
digest_size = 32
_native_type = "wc_Sha256 *"
_native_size = _ffi.sizeof("wc_Sha256")
_delete = _lib.wc_Sha256Free
_copy = _lib.wc_Sha256Copy
_delete = staticmethod(_lib.wc_Sha256Free)
_copy = staticmethod(_lib.wc_Sha256Copy)
def __del__(self):
if hasattr(self, '_native_object') and not getattr(self, '_shallow_copy', False):
@ -213,8 +213,8 @@ if _lib.SHA384_ENABLED:
digest_size = 48
_native_type = "wc_Sha384 *"
_native_size = _ffi.sizeof("wc_Sha384")
_delete = _lib.wc_Sha384Free
_copy = _lib.wc_Sha384Copy
_delete = staticmethod(_lib.wc_Sha384Free)
_copy = staticmethod(_lib.wc_Sha384Copy)
def __del__(self):
if hasattr(self, '_native_object') and not getattr(self, '_shallow_copy', False):
@ -241,8 +241,8 @@ if _lib.SHA512_ENABLED:
digest_size = 64
_native_type = "wc_Sha512 *"
_native_size = _ffi.sizeof("wc_Sha512")
_delete = _lib.wc_Sha512Free
_copy = _lib.wc_Sha512Copy
_delete = staticmethod(_lib.wc_Sha512Free)
_copy = staticmethod(_lib.wc_Sha512Copy)
def __del__(self):
if hasattr(self, '_native_object') and not getattr(self, '_shallow_copy', False):
@ -403,7 +403,7 @@ if _lib.HMAC_ENABLED:
digest_size = None
_native_type = "Hmac *"
_native_size = _ffi.sizeof("Hmac")
_delete = _lib.wc_HmacFree
_delete = staticmethod(_lib.wc_HmacFree)
def __del__(self):
if hasattr(self, '_native_object') and not getattr(self, '_shallow_copy', False):

View File

@ -44,7 +44,7 @@ class Random:
raise WolfCryptError("RNG init error (%d)" % ret)
# making sure _lib.wc_FreeRng outlives WC_RNG instances
_delete = _lib.wc_FreeRng
_delete = staticmethod(_lib.wc_FreeRng)
def __del__(self):
if self.native_object: