mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-17 19:00:58 +00:00
src/trezor/crypto: introduce SecureContext
usage: from trezor.crypto import SecureContext with SecureContext() as sc: sc.var1 = ... sc.var2 = ... SecureContext will call destructors of all variables assigned to sc in the block. It will also call gc.collect()
This commit is contained in:
parent
7b6e8a1158
commit
ebf912c8f1
@ -1,3 +1,5 @@
|
|||||||
|
from gc import collect
|
||||||
|
|
||||||
from trezorcrypto import ( # noqa: F401
|
from trezorcrypto import ( # noqa: F401
|
||||||
bip32,
|
bip32,
|
||||||
bip39,
|
bip39,
|
||||||
@ -8,3 +10,18 @@ from trezorcrypto import ( # noqa: F401
|
|||||||
random,
|
random,
|
||||||
rfc6979,
|
rfc6979,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class SecureContext:
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
|
for k in self.__dict__:
|
||||||
|
o = getattr(self, k)
|
||||||
|
if hasattr(o, "__del__"):
|
||||||
|
o.__del__()
|
||||||
|
collect()
|
||||||
|
Loading…
Reference in New Issue
Block a user