-
Notifications
You must be signed in to change notification settings - Fork 30
Wrap _delete/_copy class attrs in staticmethod so self isn't bound as an extra arg. #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
|
||
|
|
||
| def __del__(self): | ||
| if hasattr(self, '_native_object') and not getattr(self, '_shallow_copy', False): | ||
|
|
@@ -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): | ||
|
|
@@ -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): | ||
|
|
@@ -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): | ||
|
|
@@ -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): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
||
|
|
||
| def __del__(self): | ||
| if self.native_object: | ||
|
|
||
There was a problem hiding this comment.
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., checkingAesGcmStream.__dict__["_delete"]is astaticmethod, or thatinstance._delete(cdata)doesn’t passself). Adding a targeted test would help prevent future regressions across these wrappers.