|
|
@ -246,4 +246,42 @@ class CardSlot: |
|
|
|
|
|
|
|
return fname, basename+ext |
|
|
|
|
|
|
|
def securely_blank_file(full_path): |
|
|
|
# input PSBT file no longer required; so delete it |
|
|
|
# - blank with zeros |
|
|
|
# - rename to garbage (to hide filename after undelete) |
|
|
|
# - delete |
|
|
|
# - ok if file missing already (card maybe have been swapped) |
|
|
|
# |
|
|
|
# NOTE: we know the FAT filesystem code is simple, see |
|
|
|
# ../external/micropython/extmod/vfs_fat.[ch] |
|
|
|
|
|
|
|
path, basename = full_path.rsplit('/', 1) |
|
|
|
|
|
|
|
with CardSlot() as card: |
|
|
|
try: |
|
|
|
blk = bytes(64) |
|
|
|
|
|
|
|
with open(full_path, 'r+b') as fd: |
|
|
|
size = fd.seek(0, 2) |
|
|
|
fd.seek(0) |
|
|
|
|
|
|
|
# blank it |
|
|
|
for i in range((size // len(blk)) + 1): |
|
|
|
fd.write(blk) |
|
|
|
|
|
|
|
assert fd.seek(0, 1) >= size |
|
|
|
|
|
|
|
# probably pointless, but why not: |
|
|
|
os.sync() |
|
|
|
|
|
|
|
except OSError as exc: |
|
|
|
# missing file is okay |
|
|
|
if exc.args[0] == ENOENT: return |
|
|
|
raise |
|
|
|
|
|
|
|
# rename it and delete |
|
|
|
new_name = path + '/' + ('x'*len(basename)) |
|
|
|
os.rename(full_path, new_name) |
|
|
|
os.remove(new_name) |
|
|
|
# EOF |
|
|
|