1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-18 03:10: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:
Pavol Rusnak 2018-08-06 17:05:58 +02:00
parent 7b6e8a1158
commit ebf912c8f1
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -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()