A Python port of the Invisible Internet Project (I2P)
1"""Secure file and directory creation with restrictive permissions.
2
3Ported from net.i2p.util.SecureFile / SecureDirectory.
4"""
5
6from __future__ import annotations
7
8import os
9
10
11class SecureFile:
12 """Create files with mode 0600 (owner read/write only)."""
13
14 @staticmethod
15 def create(path: str) -> None:
16 """Create a file with 0600 permissions."""
17 fd = os.open(path, os.O_CREAT | os.O_WRONLY, 0o600)
18 os.close(fd)
19
20
21class SecureDirectory:
22 """Create directories with mode 0700 (owner only)."""
23
24 @staticmethod
25 def create(path: str) -> None:
26 """Create a directory with 0700 permissions."""
27 os.mkdir(path, 0o700)