Documentation
¶
Index ¶
- Variables
- func DeriveKey(password string) []byte
- func DeriveKeyArgon2(password string, salt []byte) []byte
- func FromRawTrixHeader(r io.ReaderAt, magic string) (trix.HeaderInfo, error)
- func FromTrix(data []byte, password string) (*datanode.DataNode, error)
- func FromTrixChaCha(data []byte, password string) (*datanode.DataNode, error)
- func ToRawTrix(header map[string]interface{}, magic string, payload io.Reader, w io.Writer) (int64, error)
- func ToTrix(dn *datanode.DataNode, password string) ([]byte, error)
- func ToTrixChaCha(dn *datanode.DataNode, password string) ([]byte, error)
- type Argon2Params
Constants ¶
This section is empty.
Variables ¶
var ( ErrPasswordRequired = errors.New("password is required for encryption") ErrDecryptionFailed = errors.New("decryption failed (wrong password?)") )
Functions ¶
func DeriveKey ¶ added in v0.0.2
DeriveKey derives a 32-byte key from a password using SHA-256. This is used for ChaCha20-Poly1305 encryption which requires a 32-byte key. Deprecated: Use DeriveKeyArgon2 for new code; this remains for backward compatibility.
func DeriveKeyArgon2 ¶ added in v0.3.0
DeriveKeyArgon2 derives a 32-byte key from a password and salt using Argon2id with DefaultArgon2Params. This is the recommended key derivation for new code.
func FromRawTrixHeader ¶ added in v0.5.0
FromRawTrixHeader reads a raw Trix container's header and reports where its payload starts, without reading a single payload byte.
The counterpart to FromTrix for containers written by ToRawTrix: rather than materialising a DataNode, it hands back the offset a caller needs to mmap, pread or section-read the binary tail directly.
info, err := trix.FromRawTrixHeader(f, "KVST") section := io.NewSectionReader(f, info.PayloadOffset, info.PayloadBytes)
info.PayloadBytes is best-effort — it is populated when the reader can report its own size (an *os.File or a *bytes.Reader), and is 0 otherwise.
func FromTrixChaCha ¶ added in v0.0.2
FromTrixChaCha decrypts a ChaCha-encrypted Trix byte slice back to a DataNode.
func ToRawTrix ¶ added in v0.5.0
func ToRawTrix(header map[string]interface{}, magic string, payload io.Reader, w io.Writer) (int64, error)
ToRawTrix writes a raw Trix container: the JSON header, then the payload copied straight through from reader to writer.
This is the hot-path counterpart to ToTrix. ToTrix packages a DataNode — it tars the node and optionally encrypts the tarball, which means the whole archive is resident and the stored bytes are not the caller's bytes. A consumer holding one large file (a State log, a model blob) wants neither: nothing is tarred, encrypted or compressed here, and the payload is never held in memory, so a multi-gigabyte container costs a copy buffer.
Because the binary tail is stored verbatim it can later be mapped rather than read — see FromRawTrixHeader for the offset.
src, _ := os.Open("session.mvlog")
dst, _ := os.Create("session.kv")
n, err := trix.ToRawTrix(map[string]interface{}{"kind": "state-kv"}, "KVST", src, dst)
It returns the total number of bytes written to w.
Types ¶
type Argon2Params ¶ added in v0.3.0
Argon2Params holds the tunable parameters for Argon2id key derivation.
func DecodeArgon2Params ¶ added in v0.3.0
func DecodeArgon2Params(data []byte) Argon2Params
DecodeArgon2Params reads 12 bytes (3 x uint32 little-endian) into Argon2Params.
func DefaultArgon2Params ¶ added in v0.3.0
func DefaultArgon2Params() Argon2Params
DefaultArgon2Params returns sensible default parameters for Argon2id.
func (Argon2Params) Encode ¶ added in v0.3.0
func (p Argon2Params) Encode() []byte
Encode serialises the Argon2Params as 12 bytes (3 x uint32 little-endian).