Documentation
¶
Overview ¶
Package io provides secure file read and write helpers, including path validation and secure-buffer convenience functions.
Index ¶
- Variables
- type Client
- func (c *Client) CopyFile(src, dest string) error
- func (c *Client) MkdirAll(path string) error
- func (c *Client) OpenFile(file string) (*os.File, error)
- func (c *Client) ReadDir(path string) ([]os.DirEntry, error)
- func (c *Client) ReadFile(file string) ([]byte, error)
- func (c *Client) ReadFileWithSecureBuffer(filename string) (*memory.SecureBuffer, error)
- func (c *Client) Remove(path string) error
- func (c *Client) RemoveAll(path string) error
- func (c *Client) TempDir(prefix string) (string, error)
- func (c *Client) TempFile(prefix string) (*os.File, error)
- func (c *Client) WriteFile(file string, data []byte) error
- func (c *Client) WriteFromReader(file string, reader io.Reader) error
- type Option
- func WithAllowAbsolute(allow bool) Option
- func WithAllowSymlinks(allow bool) Option
- func WithAllowedRoots(roots ...string) Option
- func WithBaseDir(baseDir string) Option
- func WithCopyVerifyChecksum(enable bool) Option
- func WithDirDisallowPerms(perms os.FileMode) Option
- func WithDirEnforceMode(enable bool) Option
- func WithDirMode(mode os.FileMode) Option
- func WithLogger(log hyperlogger.Logger) Option
- func WithOwnerGID(gid int) Option
- func WithOwnerUID(uid int) Option
- func WithReadAllowNonRegular(allow bool) Option
- func WithReadDisallowPerms(perms os.FileMode) Option
- func WithReadMaxSize(maxBytes int64) Option
- func WithRemoveWipe(enable bool) Option
- func WithTempEnforceFileMode(enable bool) Option
- func WithTempFileMode(mode os.FileMode) Option
- func WithWriteCreateExclusive(enable bool) Option
- func WithWriteDisableAtomic(disable bool) Option
- func WithWriteDisableSync(disable bool) Option
- func WithWriteEnforceFileMode(enable bool) Option
- func WithWriteFileMode(mode os.FileMode) Option
- func WithWriteMaxSize(maxBytes int64) Option
- func WithWriteSyncDir(enable bool) Option
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyPath indicates that a required path argument was empty. ErrEmptyPath = internalio.ErrEmptyPath // ErrInvalidPath indicates that a path failed validation. ErrInvalidPath = internalio.ErrInvalidPath // ErrAbsolutePathNotAllowed indicates absolute paths are disallowed by policy. ErrAbsolutePathNotAllowed = internalio.ErrAbsolutePathNotAllowed // ErrPathEscapesRoot indicates the resolved path is outside the allowed roots. ErrPathEscapesRoot = internalio.ErrPathEscapesRoot // ErrSymlinkNotAllowed indicates a symlink was encountered when disallowed. ErrSymlinkNotAllowed = internalio.ErrSymlinkNotAllowed // ErrFileTooLarge indicates a file exceeds the configured maximum size. ErrFileTooLarge = internalio.ErrFileTooLarge // ErrNonRegularFile indicates a non-regular file was encountered when disallowed. ErrNonRegularFile = internalio.ErrNonRegularFile // ErrInvalidBaseDir indicates the base directory is invalid. ErrInvalidBaseDir = internalio.ErrInvalidBaseDir // ErrInvalidAllowedRoots indicates the allowed roots list is invalid. ErrInvalidAllowedRoots = internalio.ErrInvalidAllowedRoots // ErrMaxSizeInvalid indicates the configured max size is invalid. ErrMaxSizeInvalid = internalio.ErrMaxSizeInvalid // ErrFileExists indicates a write target already exists when exclusive creation is requested. ErrFileExists = internalio.ErrFileExists // ErrSyncDirUnsupported indicates directory sync is not supported on this platform or filesystem. ErrSyncDirUnsupported = internalio.ErrSyncDirUnsupported // ErrNilReader indicates a nil reader was provided. ErrNilReader = internalio.ErrNilReader // ErrNotDirectory indicates the target path is not a directory. ErrNotDirectory = internalio.ErrNotDirectory // ErrInvalidPermissions indicates a permission mask was invalid. ErrInvalidPermissions = internalio.ErrInvalidPermissions // ErrPermissionsNotAllowed indicates a path has disallowed permissions. ErrPermissionsNotAllowed = internalio.ErrPermissionsNotAllowed // ErrInvalidOwnership indicates ownership constraints are invalid. ErrInvalidOwnership = internalio.ErrInvalidOwnership // ErrOwnershipNotAllowed indicates a path has unexpected ownership. ErrOwnershipNotAllowed = internalio.ErrOwnershipNotAllowed // ErrOwnershipUnsupported indicates ownership checks are not supported on this platform. ErrOwnershipUnsupported = internalio.ErrOwnershipUnsupported // ErrInvalidTempPrefix indicates a temp prefix was invalid. ErrInvalidTempPrefix = internalio.ErrInvalidTempPrefix // ErrChecksumMismatch indicates a checksum verification failure. ErrChecksumMismatch = internalio.ErrChecksumMismatch )
Functions ¶
This section is empty.
Types ¶
type Client ¶ added in v1.1.2
type Client struct {
// contains filtered or unexported fields
}
Client provides configured secure I/O helpers.
func NewWithOptions ¶ added in v1.1.2
NewWithOptions returns a Client configured with functional options.
func (*Client) ReadFile ¶ added in v1.1.2
ReadFile reads a file securely and returns the contents as a byte slice.
func (*Client) ReadFileWithSecureBuffer ¶ added in v1.1.2
func (c *Client) ReadFileWithSecureBuffer(filename string) (*memory.SecureBuffer, error)
ReadFileWithSecureBuffer reads a file securely and returns the contents in a SecureBuffer for better memory protection.
type Option ¶ added in v1.1.2
Option configures a Client.
func WithAllowAbsolute ¶ added in v1.1.2
WithAllowAbsolute configures absolute path policy for all operations.
func WithAllowSymlinks ¶ added in v1.1.2
WithAllowSymlinks configures symlink policy for all operations.
func WithAllowedRoots ¶ added in v1.1.2
WithAllowedRoots configures allowed roots for all operations.
func WithBaseDir ¶ added in v1.1.2
WithBaseDir configures a base directory for all operations.
func WithCopyVerifyChecksum ¶ added in v1.1.2
WithCopyVerifyChecksum configures checksum verification for copy operations.
func WithDirDisallowPerms ¶ added in v1.1.2
WithDirDisallowPerms configures disallowed permissions for directories.
func WithDirEnforceMode ¶ added in v1.1.2
WithDirEnforceMode configures directory mode enforcement.
func WithDirMode ¶ added in v1.1.2
WithDirMode configures the directory mode used for MkdirAll/TempDir.
func WithLogger ¶ added in v1.1.2
func WithLogger(log hyperlogger.Logger) Option
WithLogger configures the logger used by the client.
func WithOwnerGID ¶ added in v1.1.2
WithOwnerGID configures ownership GID checks for all operations.
func WithOwnerUID ¶ added in v1.1.2
WithOwnerUID configures ownership UID checks for all operations.
func WithReadAllowNonRegular ¶ added in v1.1.2
WithReadAllowNonRegular configures non-regular read handling.
func WithReadDisallowPerms ¶ added in v1.1.2
WithReadDisallowPerms configures disallowed permissions for reads.
func WithReadMaxSize ¶ added in v1.1.2
WithReadMaxSize configures a max size for reads.
func WithRemoveWipe ¶ added in v1.1.2
WithRemoveWipe configures best-effort wiping before removal.
func WithTempEnforceFileMode ¶ added in v1.1.2
WithTempEnforceFileMode configures file mode enforcement for temp files.
func WithTempFileMode ¶ added in v1.1.2
WithTempFileMode configures the file mode used for temp files.
func WithWriteCreateExclusive ¶ added in v1.1.2
WithWriteCreateExclusive configures exclusive create behavior.
func WithWriteDisableAtomic ¶ added in v1.1.2
WithWriteDisableAtomic configures atomic write behavior.
func WithWriteDisableSync ¶ added in v1.1.2
WithWriteDisableSync configures fsync behavior for writes.
func WithWriteEnforceFileMode ¶ added in v1.1.2
WithWriteEnforceFileMode configures file mode enforcement for writes.
func WithWriteFileMode ¶ added in v1.1.2
WithWriteFileMode configures the file mode used for writes.
func WithWriteMaxSize ¶ added in v1.1.2
WithWriteMaxSize configures a max size for writes.
func WithWriteSyncDir ¶ added in v1.1.2
WithWriteSyncDir configures parent directory sync for writes.