castrec

package
v0.154.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package castrec records a pty relay's output stream as an asciinema v2 "cast" file, optionally wrapped in a framed AES-256-GCM envelope (D-P3-4). It is a crypto-security-critical, stdlib-only package (G031): no third-party module is imported. httpapi constructs a Recorder at serve start and, per pty session, Opens a CastSink that ptyrelay writes output bytes to; on Close the sink flushes (plaintext) or seals its final authenticated frame (encrypted).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CastSink

type CastSink interface {
	io.Writer
	Close() error
	Err() error
}

CastSink is the cast recording sink returned by Recorder.Open. ptyrelay writes pty output via io.Writer and finalizes via Close; httpapi additionally consults Err() at finalize (H5). It is defined here rather than imported from ptyrelay so castrec stays leaf on the crypto side — the concrete asciicastWriter also satisfies ptyrelay's narrower {io.Writer; Close} interface (wired in T1/T5).

type DecReader

type DecReader struct {
	// contains filtered or unexported fields
}

DecReader decrypts a framed AEAD file into its plaintext stream. Read serves decrypted bytes; frames are opened on demand with a reader-tracked, strictly increasing frame index so any reorder/replay/cross-file substitution fails authentication. EOF before the authenticated final frame, or any bytes after it, is corruption.

func (*DecReader) Close

func (d *DecReader) Close() error

Close closes the optional underlying file. Safe to call once.

func (*DecReader) Read

func (d *DecReader) Read(p []byte) (int, error)

Read yields decrypted plaintext, decrypting frames as needed. It returns io.EOF only after the authenticated final frame has been consumed and the file is at physical EOF.

type EncWriter

type EncWriter struct {
	// contains filtered or unexported fields
}

EncWriter is the framed AEAD writer. Write accumulates plaintext into <=16KB frames (sealed and written as they fill); Close flushes any pending partial frame, then writes the authenticated final frame and closes the underlying file. Err() exposes the latched write error.

func (*EncWriter) Close

func (e *EncWriter) Close() error

Close flushes any pending partial frame, writes the authenticated final frame (empty plaintext, is_final=1, frame_index=total data frames) and closes the underlying file. Idempotent. On a prior write error it still closes the file but writes no final frame (the stream is already broken).

func (*EncWriter) Err

func (e *EncWriter) Err() error

Err reports the latched write/close error.

func (*EncWriter) Write

func (e *EncWriter) Write(p []byte) (int, error)

Write accumulates p into frames, sealing and writing each frame as it reaches castChunkSize. A partial frame stays buffered until Close.

type Recorder

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder is the per-serve cast recording factory. It holds the (once-derived) master key when encryption is on and mints a CastSink per pty session. A nil *Recorder is never used — httpapi injects nil to mean "recording disabled".

func New

func New(cfg config.CastConfig, secret []byte) (*Recorder, error)

New builds a Recorder from the cast config and the resolved (decoded) secret. When encryption is on it derives the master key once (HKDF); a derivation error is propagated so serve start can fail fast. secret is only consulted when both cast and encryption are enabled; its length is validated at serve start (T4).

Deviation from the plan snippet `New(...) *Recorder`: New returns an error because hkdf.Key (Go1.24+) returns (key, error) — the master-key derivation must surface its failure rather than be swallowed.

func (*Recorder) Encrypted

func (r *Recorder) Encrypted() bool

Encrypted reports whether Open produces encrypted (framed AEAD) recordings.

func (*Recorder) NewDecReader

func (r *Recorder) NewDecReader(path string) (io.ReadCloser, error)

NewDecReader opens an encrypted cast file for streaming decryption (the recording download gate, T6). The returned ReadCloser yields the decrypted asciicast bytes and closes the file on Close. It is only valid for encrypted recorders; a plaintext file is served directly (http.ServeFile) instead.

func (*Recorder) Open

func (r *Recorder) Open(path string, cols, rows int, startedAt int64) (CastSink, error)

Open creates the cast file at path and returns a CastSink. When encryption is on the asciicast stream is wrapped in an EncWriter; otherwise it is written as plaintext asciinema v2. cols/rows <= 0 fall back to 80x24 in the asciicast header. A file-create (or header-write) failure returns an error so the caller can degrade to "not recording".

Jump to

Keyboard shortcuts

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