io

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package io provides secure input/output operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyPath indicates that a required path argument was empty.
	ErrEmptyPath = ewrap.New("path cannot be empty")
	// ErrInvalidPath indicates that a path failed validation.
	ErrInvalidPath = ewrap.New("invalid path")
	// ErrAbsolutePathNotAllowed indicates absolute paths are disallowed by policy.
	ErrAbsolutePathNotAllowed = ewrap.New("absolute paths are not allowed")
	// ErrPathEscapesRoot indicates the resolved path is outside the allowed roots.
	ErrPathEscapesRoot = ewrap.New("path escapes allowed root")
	// ErrSymlinkNotAllowed indicates a symlink was encountered when disallowed.
	ErrSymlinkNotAllowed = ewrap.New("symlinks are not allowed")
	// ErrFileTooLarge indicates a file exceeds the configured maximum size.
	ErrFileTooLarge = ewrap.New("file exceeds maximum size")
	// ErrNonRegularFile indicates a non-regular file was encountered when disallowed.
	ErrNonRegularFile = ewrap.New("non-regular files are not allowed")
	// ErrInvalidBaseDir indicates the base directory is invalid.
	ErrInvalidBaseDir = ewrap.New("invalid base directory")
	// ErrInvalidAllowedRoots indicates the allowed roots list is invalid.
	ErrInvalidAllowedRoots = ewrap.New("invalid allowed roots")
	// ErrMaxSizeInvalid indicates the configured max size is invalid.
	ErrMaxSizeInvalid = ewrap.New("max size cannot be negative")
	// ErrFileExists indicates a write target already exists when exclusive creation is requested.
	ErrFileExists = ewrap.New("file already exists")
)

Functions

func SecureOpenFile added in v1.0.1

func SecureOpenFile(path string, opts ReadOptions, log hyperlogger.Logger) (*os.File, error)

SecureOpenFile opens a file for streaming reads with configurable security options.

func SecurePath

func SecurePath(path string, allowedRoots ...string) (string, error)

SecurePath validates and sanitizes a file path using default read options. It returns a resolved path or an error if validation fails.

func SecureReadFile

func SecureReadFile(path string, log hyperlogger.Logger) ([]byte, error)

SecureReadFile reads a file into memory with default secure options. Use SecureReadFileWithOptions for custom behaviors.

func SecureReadFileWithOptions added in v1.0.1

func SecureReadFileWithOptions(path string, opts ReadOptions, log hyperlogger.Logger) ([]byte, error)

SecureReadFileWithOptions reads a file into memory with configurable security options.

func SecureReadFileWithSecureBuffer

func SecureReadFileWithSecureBuffer(path string, log hyperlogger.Logger) (*memory.SecureBuffer, error)

SecureReadFileWithSecureBuffer reads a file securely and returns its contents in a SecureBuffer.

func SecureWriteFile added in v1.0.1

func SecureWriteFile(path string, data []byte, opts WriteOptions, log hyperlogger.Logger) error

SecureWriteFile writes data to a file with configurable security options.

Types

type ReadOptions added in v1.0.1

type ReadOptions struct {
	BaseDir         string
	AllowedRoots    []string
	MaxSizeBytes    int64
	AllowAbsolute   bool
	AllowSymlinks   bool
	AllowNonRegular bool
}

ReadOptions configures secure read behavior.

type WriteOptions added in v1.0.1

type WriteOptions struct {
	BaseDir         string
	AllowedRoots    []string
	MaxSizeBytes    int64
	FileMode        os.FileMode
	CreateExclusive bool
	AllowAbsolute   bool
	AllowSymlinks   bool
}

WriteOptions configures secure write behavior.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL