Documentation
¶
Overview ¶
Package tmpsecfile provides a temporary file that is anonymous on disk (unlinked or O_TMPFILE) and transparently encrypted at rest with a per-file random AES-256-CTR key. The file supports random read/write and treats sparse holes (regions never written) as zeros.
Index ¶
- type File
- func (f *File) Close() error
- func (f *File) Read(p []byte) (int, error)
- func (f *File) ReadAt(p []byte, off int64) (int, error)
- func (f *File) Seek(offset int64, whence int) (int64, error)
- func (f *File) Size() int64
- func (f *File) Truncate(size int64) error
- func (f *File) Write(p []byte) (int, error)
- func (f *File) WriteAt(p []byte, off int64) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
File is a secure anonymous temporary file. The on-disk representation is encrypted with AES-256-CTR using a key generated at New time and held only for the lifetime of this File. Logical length and the Read/Write cursor are tracked in this struct; the underlying *os.File is used purely as a backing store via ReadAt/WriteAt.
func (*File) Close ¶
Close releases the backing file. The encryption key is dropped along with the File value (no method to retrieve it exists).
func (*File) ReadAt ¶
ReadAt reads up to len(p) bytes at off, decrypting on the fly. Regions of the backing file that read as all-zero AES blocks are treated as sparse holes and returned as zeros (no decryption attempted).
Sparse detection always inspects the full 16-byte AES block on disk, even when the user's requested range covers only part of it — this is what keeps the false-positive probability at 2^-128 per block regardless of how much of the block falls inside the logical length.
func (*File) Truncate ¶
Truncate sets the logical length of the file. Extending creates a sparse hole; subsequent reads from the new region return zeros.
The on-disk size is rounded up to a multiple of the AES block so ReadAt's sparse check always has 16 bytes of evidence. When shrinking past a partial block, the bytes between the new length and the next block boundary are re-encrypted as zeros so a later re-extension doesn't surface old plaintext.
func (*File) WriteAt ¶
WriteAt encrypts p with the keystream at off and writes it to the backing file. Length is updated to reflect the highest written byte.
Writes that touch only part of an AES block read-modify-write the whole block, so every block on disk is either fully encrypted (real ciphertext) or fully sparse (raw zeros). That invariant is what lets ReadAt distinguish written-zeros from never-written holes by inspecting the on-disk bytes alone.