Securefile Handler Modules

Securefile handler

This is main module that should be used.

securefile_handler.securefile_handler.move_file(src: Union[str, pathlib.Path], dst: Union[str, pathlib.Path], erase_function: callable = <function shred>)

Function that moves only regular file to another device.

Function copy file to another device and delete file on source path.

If source file is symbolic link, the content of the file pointed to by symlink will be copied and old one will be destroyed together with symbolic link.

File operation exceptions are not handled.

Parameters:
  • src – Source path of file.
  • dst – Destination path of file.
  • erase_function – Function for erasing data in files. This optional argument is a callable.
securefile_handler.securefile_handler.move_folder(src_dir: Union[str, pathlib.Path], dst_dir: Union[str, pathlib.Path], erase_function: callable = <function shred>)

Function that moves folder with its content to another device.

The destination directory, named by dst, must not already exist.

This function will copy folder with content and then delete the old folder with content.

If destination does not exists, new folder folder will be created

If folder contains symlinks, the contents of the files pointed to by symlinks are copied.

Directory operation exceptions are not handled.

Parameters:
  • src_dir – Source path of directory.
  • dst_dir – Destination path of directory.
  • erase_function – Function for erasing data in files.
securefile_handler.securefile_handler.remove_dirtree(dirpath: Union[str, pathlib.Path], erase_function: callable = <function shred>)

Function to remove folder with its content securely.

Folder must contain some files.

If folder contains symlinks pointing to regular files, only symlinks will be destroyed.

File and directory operation exceptions are not handled.

Parameters:
  • dirpath – Path to non-empty directory
  • erase_function – Function for erasing data in files.
securefile_handler.securefile_handler.remove_file(filepath: Union[str, pathlib.Path], erase_function: callable = <function shred>)

Function that removes securely file specified in parameter.

If file path is symlink function will delete file that symlink points to and symlink will be deleted too.

File operation exceptions are not handled.

Parameters:
  • filepath – Path to file specified with Path class or string.
  • erase_function – Function for erasing data in files.
securefile_handler.securefile_handler.shred(filepath: Union[str, pathlib.Path], erase_function: callable = <function shred>)

Function to shred file content.

If filepath is symbolic link, file will be shred that symlink points to.

File operation exceptions are not handled.

Parameters:
  • filepath – Path to file specified with Path class or string.
  • erase_function – Function for erasing data in file.

Erase helpers

securefile_handler.erase_helpers.remove_dirtree(dirpath: pathlib.Path, erase_function: callable = <function shred>)

Function to help remove directory tree

Parameters:
  • dirpath – Path to root directory specified with Path class
  • erase_function – Function for erasing data in files.
securefile_handler.erase_helpers.shred(filepath: pathlib.Path, chunk_size=4096)

Function, that securely shreds file.

File operation exceptions are not handled.

Parameters:
  • filepath – Path class with filepath
  • chunk_size – Size of chunk for amount of bytes rewritten at once. Consider changing this value.

This may slow your device.

Erase helpers cythonized

This module defines functions for safe file erasing. Algorithm for erasing is defined by British HMG Infosec Standard 5, Enhanced Standard. Algorithm pseudocode:

Open file

In first round rewrite all bytes to zeros

In second round rewrite all bytes to ones

In third round rewrite all bytes to random values

Algorithm is defined in shred_file function.

securefile_handler._erase_helpers.shred_file()

Cythonized function for shredding file.

Parameters:
  • path – String path to file
  • file_size – Size of file in bytes
  • chunk_size – Size of chunk in bytes

Module with errors

exception securefile_handler.errors.CannotBeShred
exception securefile_handler.errors.CannotReadFileError
exception securefile_handler.errors.EmptyFolderError
exception securefile_handler.errors.EraseFunctionError
exception securefile_handler.errors.NotAFileError
exception securefile_handler.errors.SameDirectoryError
exception securefile_handler.errors.SameDriveError
exception securefile_handler.errors.SameFileError
exception securefile_handler.errors.SubDirectoryError
exception securefile_handler.errors.WrongFilepathType