"""Secure file and directory creation with restrictive permissions. Ported from net.i2p.util.SecureFile / SecureDirectory. """ from __future__ import annotations import os class SecureFile: """Create files with mode 0600 (owner read/write only).""" @staticmethod def create(path: str) -> None: """Create a file with 0600 permissions.""" fd = os.open(path, os.O_CREAT | os.O_WRONLY, 0o600) os.close(fd) class SecureDirectory: """Create directories with mode 0700 (owner only).""" @staticmethod def create(path: str) -> None: """Create a directory with 0700 permissions.""" os.mkdir(path, 0o700)