Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/veracrypt/veracrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ def _validate_keyfiles(self, keyfiles: Optional[List[str]], context: str) -> Non
for keyfile in keyfiles:
self._check_path(keyfile)

@staticmethod
def _validate_size(size: int) -> None:
"""Validate volume size is a positive integer."""
if not isinstance(size, int) or size <= 0:
raise ValueError("Volume size must be a positive integer.")

@staticmethod
def _validate_volume_parent_dir(volume_path: str) -> None:
"""Ensure the parent directory for a volume path exists."""
parent_dir = os.path.dirname(volume_path) or "."
if not os.path.exists(parent_dir):
raise VeraCryptError(
f"The parent directory for {volume_path} does not exist."
)

@staticmethod
def _mask_password_in_args(args: List[str], password: str, index: int) -> None:
"""Safely mask a password in a command args list."""
Expand Down Expand Up @@ -187,6 +202,8 @@ def mount_volume(
self.logger.debug("Mounting volume")
self._validate_options(options, "mount_volume")
self._check_path(volume_path)
if self.os_name != "Windows" and mount_point:
self._check_path(mount_point)

if self.os_name == "Windows":
cmd = self._mount_win(volume_path, password, mount_point, options)
Expand Down Expand Up @@ -352,6 +369,8 @@ def create_volume(
self.logger.debug("Creating volume")
self._validate_options(options, "create_volume")
self._validate_keyfiles(keyfiles, "create_volume")
self._validate_size(size)
self._validate_volume_parent_dir(volume_path)

if self.os_name == "Windows":
cmd = self._create_win(
Expand Down
Loading