earwax.vault_file module¶
Provides the VaultFile class.
-
exception
earwax.vault_file.
IncorrectVaultKey
¶ Bases:
Exception
The wrong key was given, and the file cannot be decrypted.
-
class
earwax.vault_file.
VaultFile
(entries: Dict[str, Union[bytes, List[bytes]]] = NOTHING)¶ Bases:
object
A class for restoring hidden files.
This class is used for loading files hidden by the
earwax vault
command.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}
, wheredata
is 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
entries
dictionary, 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
entries
dictionary.If
None
is provided, a string representation of the path will be used.If
None
is given, and thep
is not a singlePath
instance,RuntimeError
will be raised.
- p –
-
classmethod
from_path
(filename: pathlib.Path, key: bytes) → earwax.vault_file.VaultFile¶ Load a series of files and return a
VaultFile
instance.Given a path to a data file, and the correct key, load a series of files and return a
VaultFile
instance.If the key is invalid,
earwax.InvalidFaultKey
will 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 new
command. - 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.
-