shred_file(): add cfg, iterations params

This commit is contained in:
The MMGen Project 2025-06-21 11:14:08 +00:00
commit 2df03306f2
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
4 changed files with 8 additions and 8 deletions

View file

@ -242,7 +242,7 @@ class Signable:
do_exit = True)
for fn in files:
msg(f'Shredding file ‘{fn}')
shred_file(fn)
shred_file(self.cfg, fn, iterations=15)
sys.exit(0)
async def get_last_created(self):
@ -694,7 +694,7 @@ class Autosign:
def wipe_encryption_key(self):
if self.keyfile.exists():
ymsg(f'Shredding wallet encryption key ‘{self.keyfile}')
shred_file(self.keyfile, verbose=self.cfg.verbose)
shred_file(self.cfg, self.keyfile)
else:
gmsg('No wallet encryption key on removable device')
@ -820,7 +820,7 @@ class Autosign:
def do_shred(fn):
nonlocal count
msg_r('.')
shred_file(fn, verbose=self.cfg.verbose)
shred_file(self.cfg, fn, iterations=15)
count += 1
def clean_dir(s_name):

View file

@ -57,12 +57,12 @@ def check_binary(args):
die(2, f'{args[0]!r} binary missing, not in path, or not executable')
set_vt100()
def shred_file(fn, *, verbose=False):
def shred_file(cfg, fn, *, iterations=30):
check_binary(['shred', '--version'])
from subprocess import run
run(
['shred', '--force', '--iterations=30', '--zero', '--remove=wipesync']
+ (['--verbose'] if verbose else [])
['shred', '--force', f'--iterations={iterations}', '--zero', '--remove=wipesync']
+ (['--verbose'] if cfg.verbose else [])
+ [str(fn)],
check=True)
set_vt100()

View file

@ -241,7 +241,7 @@ if invoked_as == 'passchg':
def secure_delete(fn):
bmsg('Securely deleting old wallet')
from .fileutil import shred_file
shred_file(fn, verbose = cfg.verbose)
shred_file(cfg, fn)
def rename_old_wallet_maybe(silent):
# though very unlikely, old and new wallets could have same Key ID and thus same filename.

View file

@ -79,6 +79,6 @@ class OpCreateOffline(OpCreate):
if f.name.endswith(vkf.ext):
from ...fileutil import shred_file
msg(f'\nShredding old viewkey-address file ‘{f}')
shred_file(f, verbose=self.cfg.verbose)
shred_file(self.cfg, f, iterations=15)
vkf.write(outdir=self.asi.xmr_dir)