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 ¶
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.
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 ¶
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).
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 ¶
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 ¶
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".