Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
src/trezor/crypto: introduce SecureContext
Browse files Browse the repository at this point in the history
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()
  • Loading branch information
prusnak committed Aug 6, 2018
1 parent 7b6e8a1 commit ebf912c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/trezor/crypto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from gc import collect

from trezorcrypto import ( # noqa: F401
bip32,
bip39,
Expand All @@ -8,3 +10,18 @@
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()

0 comments on commit ebf912c

Please sign in to comment.