Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions wolfcrypt/ciphers.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class AesGcmStream:
_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)
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the same method-binding issue for _delete, but there’s no regression test covering it (e.g., checking AesGcmStream.__dict__["_delete"] is a staticmethod, or that instance._delete(cdata) doesn’t pass self). Adding a targeted test would help prevent future regressions across these wrappers.

Copilot uses AI. Check for mistakes.

def __init__(self, key, IV, tag_bytes=16):
"""
Expand Down Expand Up @@ -698,7 +698,7 @@ def __init__(self):
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:
Expand Down Expand Up @@ -1057,7 +1057,7 @@ def __init__(self):
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:
Expand Down Expand Up @@ -1423,7 +1423,7 @@ def __init__(self):
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:
Expand Down Expand Up @@ -1623,7 +1623,7 @@ def __init__(self):
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:
Expand Down
18 changes: 9 additions & 9 deletions wolfcrypt/hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ class Sha(_Hash):
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)
Comment on lines +160 to +161
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These _delete/_copy wrappers prevent accidental instance-binding, but there’s no explicit regression test for this behavior (e.g., asserting Sha.__dict__["_delete"]/Sha.__dict__["_copy"] are staticmethods). Consider adding a small unit test to lock in the intended calling convention.

Copilot uses AI. Check for mistakes.

def __del__(self):
if hasattr(self, '_native_object') and not getattr(self, '_shallow_copy', False):
Expand All @@ -185,8 +185,8 @@ class Sha256(_Hash):
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):
Expand All @@ -213,8 +213,8 @@ class Sha384(_Hash):
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):
Expand All @@ -241,8 +241,8 @@ class Sha512(_Hash):
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):
Expand Down Expand Up @@ -403,7 +403,7 @@ class _Hmac(_Hash):
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):
Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, nonce=_ffi.NULL, device_id=_lib.INVALID_DEVID):
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)
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change fixes method-binding of _delete, but there’s no regression test ensuring _delete remains wrapped (e.g., asserting Random.__dict__["_delete"] is a staticmethod or that calling rng._delete(...) does not inject self). Adding a focused test would prevent this from regressing again.

Copilot uses AI. Check for mistakes.

def __del__(self):
if self.native_object:
Expand Down
Loading