earwax.vault_file module¶
Provides the VaultFile class.
-
exception
earwax.vault_file.IncorrectVaultKey¶ Bases:
ExceptionThe wrong key was given, and the file cannot be decrypted.
-
class
earwax.vault_file.VaultFile(entries: Dict[str, Union[bytes, List[bytes]]] = NOTHING)¶ Bases:
objectA class for restoring hidden files.
This class is used for loading files hidden by the
earwax vaultcommand.Most of the time, you want to create instances with the
from_path()constructor.To add files, use the
add_path()method.Variables: entries – The files which you are saving.
The format of this dictionary is
{label: data}, wheredatais the contents of the file you added.Labels don’t necessarily have to be the names of the files they represent. They can be whatever you like.
-
add_path(p: Union[pathlib.Path, Generator[pathlib.Path, None, None]], label: Optional[str] = None) → str¶ Add a file or files to this vault.
This method will add the contents of the given file to the
entriesdictionary, using the given label as the key.Parameters: - p –
The path to load.
If the provided value is a generator, the resulting dictionary value will be a list of the contents of every file in that iterator.
If the provided value is a directory, then the resulting dictionary value will be a list of every file (not subdirectory) in that directory.
- label –
The label that will be given to this entry.
This value will be the key in the
entriesdictionary.If
Noneis provided, a string representation of the path will be used.If
Noneis given, and thepis not a singlePathinstance,RuntimeErrorwill be raised.
- p –
-
classmethod
from_path(filename: pathlib.Path, key: bytes) → earwax.vault_file.VaultFile¶ Load a series of files and return a
VaultFileinstance.Given a path to a data file, and the correct key, load a series of files and return a
VaultFileinstance.If the key is invalid,
earwax.InvalidFaultKeywill be raised.Parameters: - filename –
The name of the file to load.
This must be a data file, generated by a previous call to
earwax.VaultFile.save(), not a yaml file as created by theearwax vault newcommand. - key – The decryption key for the given file.
- filename –
-
save(filename: pathlib.Path, key: bytes) → None¶ Save this instance’s entries to a file.
Path filename: The data file to save to.
The contents of this file will be encrypted with the given key, and will be binary.
Parameters: key –
The key to use to encrypt the data.
This key must either have been generated by
cryptography.fernet.Fernet.generate_key, or be of the correct format.
-