diff --git a/src/trezor/crypto/__init__.py b/src/trezor/crypto/__init__.py index 7eb67a3d99..254bc3f3d9 100644 --- a/src/trezor/crypto/__init__.py +++ b/src/trezor/crypto/__init__.py @@ -1,3 +1,5 @@ +from gc import collect + from trezorcrypto import ( # noqa: F401 bip32, bip39, @@ -8,3 +10,18 @@ from trezorcrypto import ( # noqa: F401 random, 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()