Documentation
¶
Overview ¶
Package temari wraps the Temari cdylib (libtemari.so / .dylib / temari.dll) with a cgo-free FFI. No C toolchain is required: the package builds and runs with CGO_ENABLED=0, for static binaries and cross-compilation.
The library performs **no network requests**: construct a template from a 40020-style key-server JSON response body with FromJSON — fetch the JSON yourself (own HTTP client) and pass it here.
Loading is platform-specific (see loader_unix.go / loader_windows.go):
- Linux / macOS / FreeBSD: purego `Dlopen` to open the library
- Windows: `golang.org/x/sys/windows` `LoadDLL` to open the library (purego supports Windows, but has no `Dlopen` there)
On every platform symbols are bound with purego `RegisterLibFunc` (its loadSymbol is dlopen/dlsym on unix, GetProcAddress on Windows), and all calls go through purego's cgo-free calling convention.
Build the library first:
cd <temari repo> && cargo build --release # -> libtemari.so / temari.dll
Then load it once:
lib, err := temari.Load("/path/to/libtemari.so") // or temari.dll on Windows
t, err := lib.FromJSON(jsonBody) // caller fetched the JSON
plain, err := t.Decrypt(sample)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BundledLibraryPath ¶ added in v0.2.0
BundledLibraryPath returns the path of the cdylib bundled with this module for the current platform, or an error if none is present.
Types ¶
type Library ¶
type Library struct {
// contains filtered or unexported fields
}
Library is the loaded temari cdylib. Call Load once and reuse the returned Library. `handle` is the module handle (dlopen on unix; LoadLibrary on Windows).
func Load ¶
Load opens the temari cdylib from path. Returns an error if the library or any required symbol is missing.
func LoadDefault ¶ added in v0.2.0
LoadDefault loads the cdylib bundled with this module for the current platform. For un-precompiled platforms it falls back to compiling the embedded Rust source with `cargo` (cached under the user cache dir). Prefer it over Load(path) when using the distributed package.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream is an incremental parallel decryptor with in-order results.
Submit encrypted samples as they arrive, then receive plaintexts in submission order. Blocking at the library level; wrap with C() for asynchronous consumption (goroutine + channel).
func (*Stream) C ¶
C returns a channel that receives plaintexts in order until the stream is closed (the channel is then closed). A pump goroutine does the blocking Next() calls off the caller's goroutine.
func (*Stream) Finish ¶
func (s *Stream) Finish()
Finish closes the input side; already-submitted samples still drain.
func (*Stream) Next ¶
Next blocks for the next plaintext (in order). ok=false once the stream is closed and everything is consumed.
func (*Stream) TryNext ¶
func (s *Stream) TryNext() (plain []byte, state StreamState)
TryNext is a non-blocking probe.
type StreamState ¶
type StreamState int
StreamState is the result of a non-blocking Stream.TryNext.
const ( // StreamData: a plaintext is ready. StreamData StreamState = iota // StreamEmpty: no plaintext pending yet (stream still open). StreamEmpty // StreamClosed: the stream is closed and consumed. StreamClosed )
type Temari ¶
type Temari struct {
// contains filtered or unexported fields
}
Temari is an opaque decryption template handle. Thread-safe for concurrent Decrypt calls; free with Close.
func (*Temari) Close ¶
func (t *Temari) Close()
Close frees the template handle (nil-safe, idempotent).
func (*Temari) DecryptPar ¶
DecryptPar decrypts a batch of independent samples in parallel, preserving order. Each sample is an independent SAMPLE-AES unit (state resets per sample), so a whole stream can be split at fragment boundaries and decrypted across all cores.
Default fast path: samples are read via scattered pointers (no input join memcpy) by decrypt_samples_par; plaintexts land in one flat buffer which is sliced into the returned views.