From f6c27bf55dd9dd551e110055244582367d16c05c Mon Sep 17 00:00:00 2001 From: Kareem Date: Wed, 22 Apr 2026 16:19:41 -0700 Subject: [PATCH] Wrap _delete/_copy class attrs in staticmethod so self isn't bound as an extra arg. Fixes #108. --- wolfcrypt/ciphers.py | 10 +++++----- wolfcrypt/hashes.py | 18 +++++++++--------- wolfcrypt/random.py | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/wolfcrypt/ciphers.py b/wolfcrypt/ciphers.py index 77ea987..4027065 100644 --- a/wolfcrypt/ciphers.py +++ b/wolfcrypt/ciphers.py @@ -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: diff --git a/wolfcrypt/hashes.py b/wolfcrypt/hashes.py index 92adac3..d4a3d19 100644 --- a/wolfcrypt/hashes.py +++ b/wolfcrypt/hashes.py @@ -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): diff --git a/wolfcrypt/random.py b/wolfcrypt/random.py index 17d3ae7..7525eae 100644 --- a/wolfcrypt/random.py +++ b/wolfcrypt/random.py @@ -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: