Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
63ddd0a
refactor(go): copy vitaminc's Go frame codec and value model into the…
coderdan Nov 27, 2026
3ae328e
refactor(go): make the copied codec one internal package, frame
coderdan Nov 27, 2026
3a0f0df
refactor(go): drop what only vitaminc's own binding needed from frame
coderdan Nov 27, 2026
c07f813
refactor(go): build the module against internal/frame, not vitaminc
coderdan Nov 27, 2026
9d9fb77
feat(go)!: give encrypt's value types, Encryptable and Encoder types …
coderdan Nov 27, 2026
e6f5916
build(go): drop the vitaminc requirements, and the release rule that …
coderdan Nov 27, 2026
62c9f30
ci(go): fuzz the frame codec's decoders in the nightly Go campaign
coderdan Nov 27, 2026
d7a3c90
docs(go): say where the frame codec lives, and record the breaking ch…
coderdan Nov 27, 2026
5b860a6
Merge remote-tracking branch 'origin/next' into refactor/go-frame-cod…
coderdan Nov 27, 2026
1ad6005
ci(go): start the Go tests when the value corpus changes
coderdan Nov 27, 2026
23569b3
test(go): skip the frame corpora outside the repository, not fail
coderdan Nov 27, 2026
9be31bb
fix(go): name the program's own type when a storage blob refuses a value
coderdan Nov 27, 2026
b3981ee
docs: stop naming vitaminc's Go packages where the Go SDK's codec is …
coderdan Nov 27, 2026
8d51ca9
fix(go): the zero Encoder does not panic, and frame has one Encryptable
coderdan Nov 27, 2026
316207d
fix(go): name encrypt, not frame, in the value types' errors
coderdan Nov 27, 2026
311320f
fix(go): refuse a nil Encryptable on a field with no declared type
coderdan Nov 27, 2026
061da75
docs(go): describe QueryTerm's document input without naming frame.Ob…
coderdan Nov 27, 2026
95a739b
ci(go): build no guest for the frame fuzz targets, and drop a stale r…
coderdan Nov 27, 2026
c4f22d5
docs(go): changelog for the Encoder, value errors and nil Encryptable
coderdan Nov 27, 2026
aa56a6c
docs(go): write the frame codec's comments in plain language
coderdan Nov 28, 2026
bb732be
docs(go): write the SDK comments about its value types in plain language
coderdan Nov 28, 2026
9ef44b4
docs(go): plain language in the Rust and CI comments about the Go codec
coderdan Nov 28, 2026
ca2c3f7
docs(go): plain language for the changelog and docs of the frame code…
coderdan Nov 28, 2026
e753e68
fix(golang): write the frame codec's error messages in plain language
coderdan Nov 28, 2026
e09a08a
Merge next into refactor/go-frame-codec-in-module
coderdan Nov 28, 2026
a4d45c4
Merge next into refactor/go-frame-codec-in-module
coderdan Nov 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ name: Fuzz
# cache, so coverage compounds; it is minimised with `cargo fuzz cmin`, and
# any crash reproducer is uploaded as an artifact.
#
# * go-fuzz-campaign (schedule and manual, never on PRs): the same for the
# Go fuzz targets in languages/golang, which fuzz the WASI guests' ABI
# from the host side (`mise run go:fuzz`). Their regression replay is
# plain `go test`, in tests-golang.yml.
# * go-fuzz-campaign (schedule and manual, never on PRs): the same run for
# the Go fuzz targets in languages/golang (`mise run go:fuzz`). Those
# targets fuzz the ABI of the WASI guests from the host side, and the
# decoders of the frame codec. Their regression replay is plain
# `go test`, in tests-golang.yml.
#
# cargo-fuzz needs nightly; the tasks run `cargo +nightly fuzz`. Pull requests
# are the only filtered event, so `push` has no filter to mirror; recorded in
Expand Down Expand Up @@ -258,11 +259,15 @@ jobs:
strategy:
fail-fast: false
matrix:
# `guest` is the build the target's package runs.
# `guest` is the guest build that the package of the target runs. The
# targets of the frame codec, in internal/frame, run no guest.
include:
- { target: FuzzGuestExportPairs, slug: encrypt-export-pairs, guest: "wasm:guest:build:deterministic" }
- { target: FuzzGuestBufferRegistry, slug: encrypt-buffer-registry, guest: "wasm:guest:build:deterministic" }
- { target: FuzzAuthGuestExportPairs, slug: auth-export-pairs, guest: "wasm:auth-guest:build" }
- { target: FuzzUnmarshal, slug: frame-value, guest: "" }
- { target: FuzzUnmarshalCipherText, slug: frame-ciphertext, guest: "" }
- { target: FuzzUnmarshalStorage, slug: frame-storage, guest: "" }
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
Expand All @@ -278,13 +283,15 @@ jobs:
cache_key_prefix: mise-v1-ubuntu-2404

- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
if: matrix.guest != ''
with:
workspaces: |
languages/golang/encrypt/guest
languages/golang/auth/guest
key: go-fuzz-${{ matrix.slug }}

- name: Build the guest (${{ matrix.slug }})
if: matrix.guest != ''
run: mise run ${{ matrix.guest }}

- name: Find the Go fuzz cache
Expand Down
16 changes: 9 additions & 7 deletions .github/workflows/release-golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ name: Release (Go)
#
# gh workflow run release-golang.yml -f version=0.1.0-alpha.1 --ref <branch>
#
# The ref must carry the EQL v4 bundle (packages/eql's v4 build), or the
# build job stops at "Build the EQL SQL bundles". Its
# languages/golang/CHANGELOG.md must have a `## [<version>]` section, which
# becomes the release notes, or the run stops at the `notes` job. A version with a pre-release
# suffix may be cut from any branch and is published as a GitHub pre-release;
# a final version is cut from main only, and not while go.mod pins vitaminc's
# Go bindings at a pseudo-version (scripts/go-release-version.mjs).
# The ref must have the EQL v4 bundle (the v4 build of packages/eql). Without
# it, the build job stops at "Build the EQL SQL bundles". The file
# languages/golang/CHANGELOG.md at the ref must have a `## [<version>]` section.
# That section becomes the release notes. Without it, the run stops at the
# `notes` job.
#
# A version with a pre-release suffix can be released from any branch. The
# workflow publishes it as a GitHub pre-release. A final version can be released
# only from main.
#
# Four jobs, split by what they may touch:
#
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/tests-golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ on:
- packages/stack-kms/**
- packages/stack-encrypt/**
- conformance/stack-encrypt/**
# internal/frame's tests read the value corpus.
- conformance/vitaminc-aead/**
- packages/stack-encrypt-derive/**
- packages/stack-encrypt-jsonpath/**
- packages/stack-guest-abi/**
Expand Down Expand Up @@ -88,6 +90,8 @@ on:
- packages/stack-kms/**
- packages/stack-encrypt/**
- conformance/stack-encrypt/**
# internal/frame's tests read the value corpus.
- conformance/vitaminc-aead/**
- packages/stack-encrypt-derive/**
- packages/stack-encrypt-jsonpath/**
- packages/stack-guest-abi/**
Expand Down
8 changes: 5 additions & 3 deletions AGENTS.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion conformance/stack-encrypt/exchange-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mise run test:conformance:exchange
|---|---|---|
| `values` | One record per positive case of `v1/record-values-v1.cases.json` (the value-boundary corpus), under the plan that case declares, with context `["conformance", "exchange"]`: the sealed leaf and every declared index term; nothing for a SQL null | The record opens to the case's typed input. Every stored term equals the term the consumer's own query of the same value derives (`eq` for equality, `lt` for an order index), and the `equal_query` spelling derives the same equality term. |
| `record` | The rows of the corpus's one record: a passthrough `int64` id (held on the host by Go, lowered as a `passthrough` output by Rust), text, `uint32`, decimal, date and timestamp fields with equality and order terms, a SQL-null text field and a sealed-null `float32` field, under context `["conformance", "exchange", "people"]` | The passthrough carried equals the corpus input; every sealed field opens to its input, a sealed null opens as null and a SQL null is absent from storage and opens as null; every stored term equals the consumer's derived query term |
| `blobs` | A whole struct (`name`, `age`, `tags`, optional `nickname`) as one opaque ciphertext under `["conformance", "exchange", "blob"]`, field `value`: Rust through `OpaqueBlob<T>`, Go through the storage blob the generated opaque path writes (`vcffi.MarshalStorage` sealed as the one `bytes` field) | The ciphertext opens and decodes to the corpus value through the other SDK's opaque reader (`OpaqueBlob<T>` or `gensupport.Opaque`). A nil Go slice and an empty Rust `Vec` are one value; Rust's `Some` marker and Go's bare pointer are one value |
| `blobs` | A whole struct (`name`, `age`, `tags`, optional `nickname`) as one opaque ciphertext under `["conformance", "exchange", "blob"]`, field `value`. Rust writes it through `OpaqueBlob<T>`. Go writes it through the generated opaque path, as a blob in the storage profile, sealed as the one `bytes` field | The ciphertext opens and decodes to the corpus value through the other SDK's opaque reader (`OpaqueBlob<T>` or `gensupport.Opaque`). A nil Go slice and an empty Rust `Vec` are one value; Rust's `Some` marker and Go's bare pointer are one value |
| `eql-rows` | The EQL v4 `profiles` rows: every column of the committed fixture's plaintexts sealed afresh, Rust through eql-bindings' typed targets, Go through its generated code | Each column opens to the plaintext through the other side's typed target, and each equality column's stored `hm` equals the term the consumer's own equality query derives for that plaintext (the generated `*Eq` query in Go, the typed `*EqQuery` target in Rust) |

Each kind runs Go to Rust and Rust to Go. Ciphertext bytes are never
Expand Down
13 changes: 8 additions & 5 deletions conformance/vitaminc-aead/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Value conformance corpus

`value-conformance.json` holds the shared vectors that Rust, Node, the Go
codec and the Go WASM encryption guest all check. Payload bytes are frozen by
`value-conformance.json` contains the shared vectors that three codecs
check: Rust, Node, and the Go frame codec in
`languages/golang/internal/frame`.

Payload bytes are frozen by
`vitaminc-aead`'s scalar tag table and leaf codec ([`vitaminc-aead`'s ADR 0001](../../packages/vitaminc-aead/docs/adr/0001-describe-plaintext-once-and-consume-it-with-sinks.md)
section 3):
fixed-width integers and float bits are little-endian, dates count days from
Expand Down Expand Up @@ -87,9 +90,9 @@ without their transport decoder, then check both directions: decoding the
bytes gives that value, and encoding that value gives the bytes. A bug that
decodes and encodes symmetrically wrong therefore still fails. Adding a kind
means teaching each language's `expected` helper to build it. The Go fuzz
targets seed themselves from `vectors`, `malformed`, `normalized` and
`ciphertext_malformed`, so every row is also a starting point for the
differential run against the guest.
targets take their seeds from `vectors`, `malformed`, `normalized`, and
`ciphertext_malformed`. Every row is therefore also a starting input for
fuzzing the Go decoders.

These are the scalar/value-level vectors needed by #375 and #414. The wider
#332 cross-language ciphertext, guest-object and SDK corpus remains separate
Expand Down
29 changes: 28 additions & 1 deletion docs/fuzzing.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,34 @@ The fuzz tests never pass a pair inside memory but outside the host's own
buffers. That breaks the host's side of the contract: an export that wipes
its input would zero the guest's own memory.

Run them with mise, after building the guests:
## Go: fuzzing the frame codec

The Go frame codec, `languages/golang/internal/frame`, decodes bytes that
the guest wrote and blobs read from a database. The decoders treat that
input as hostile. Three fuzz targets check two rules for each decoder:

- The decoder must not panic.
- Any input that the decoder accepts must be written back as the same
bytes.

Some changes to the bytes are allowed, because a Go value cannot avoid
them. For example, an `undefined` comes back as null. A timestamp in
seconds, milliseconds, or microseconds comes back in nanoseconds.

The targets need no guest. The seeds come from two files: the value corpus,
`conformance/vitaminc-aead/value-conformance.json`, and the storage corpus,
`packages/recipher-frame/testdata/storage-v1.json`.

| Go fuzz target | package | what it decodes |
|---|---|---|
| `FuzzUnmarshal` | `internal/frame` | a value frame (`Unmarshal`) |
| `FuzzUnmarshalCipherText` | `internal/frame` | a ciphertext tree (`UnmarshalCipherText`) |
| `FuzzUnmarshalStorage` | `internal/frame` | a storage blob (`UnmarshalStorage`) |

## Running the Go targets

Run them with mise. Build the guests first for the targets that call a
guest. The targets of the frame codec need no guest.

```bash
mise run wasm:guest:build:deterministic
Expand Down
31 changes: 31 additions & 0 deletions docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,37 @@ The work:
5. Delete `vcencrypt` and its guest from vitaminc. It was a demonstration of
the approach, and the Go module replaces it.

### Done

Items 1 to 4 are done, on the branch `refactor/go-frame-codec-in-module`:

- The two packages are now one internal package,
`languages/golang/internal/frame`. The package has the codec, the storage
profile, and the value model. All three were copied from vitaminc commit
`f1fc9ae74`, with their tests and fuzz targets. The tests read the value
corpus (`conformance/vitaminc-aead`) and the storage corpus
(`packages/recipher-frame/testdata`) from this repository.
- `encrypt.Date`, `Decimal`, `Int128`, and `Uint128` are now types of
package `encrypt`. `encrypt.UUID`, `Encryptable`, and `Encoder` are new.
Each value type has the same underlying type as the matching type of the
codec. `frame.Publish` registers each pair with the codec. The codec then
encodes the `encrypt` type, and decodes to it.
- The sealed leaf family, `VCValueLeaves`, `TypedNull`, `FixedWidth`, and
`FixedType` are removed. The typed null for a nil pointer is built from
the tag table, so the codec has no list of types. `record.Kind` is the
only list of type names.
- No `go.mod` names a vitaminc module: not the one of the module, and not
those of its two nested modules. `scripts/go-release-version.mjs` no
longer refuses a final version because of a vitaminc pin.
- The Go campaign in `fuzz.yml` fuzzes the three decoders every night.

Two things are still to do:

- Item 5, in vitaminc.
- The differential fuzzers that compared the Go codec with a Rust guest, in
vitaminc's `vcencrypt`. Those fuzzers could run against
`languages/golang/encrypt/guest`.

## What waits on this plan

- The TypeScript SDK: #1775, #1776 and the prototype #1829.
Expand Down
7 changes: 7 additions & 0 deletions languages/golang/.golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ linters:
- path: (_test\.go|internal/guesttest/)
linters:
- gosec
# The frame codec converts between integer widths on purpose. The codec
# reads and writes integers in two's complement. The codec also checks
# every length and count against a limit before it converts one.
- path: internal/frame/
linters:
- gosec
text: G115

formatters:
enable:
Expand Down
77 changes: 71 additions & 6 deletions languages/golang/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,25 @@ and `languages/golang/encrypt/encrypttest/vX.Y.Z` on the same commit.

### Added

- `gensupport.UUID`, the kind `"uuid"`: a field the engine seals and
opens as a UUID, sixteen bytes under vitaminc's UUID logical type. It
takes an equality index and no order or match index. Its value is a
`vcvalue.UUID`, or a value of any type whose underlying type is
`[16]byte` (`github.com/google/uuid.UUID`, say), which is converted to
one. `stashgen` does not yet map a Go type to it.
- `gensupport.UUID`, the kind `"uuid"`: a field that the engine seals and
opens as a UUID. A UUID is sixteen bytes with the logical type UUID. The
field takes an equality index, and no order or match index. The value of
the field is an `encrypt.UUID`. A value of any other type whose
underlying type is `[16]byte`, such as `github.com/google/uuid.UUID`, is
converted to an `encrypt.UUID`. `stashgen` does not yet map a Go type to
this kind.
- `encrypt.UUID`, with `ParseUUID` and `String`: sixteen bytes that are
sealed as a UUID. An opened UUID has this type.
- `encrypt.Encryptable` and `encrypt.Encoder`, for a type that writes its
own value. Give the type a method `EncryptValue(enc encrypt.Encoder)
error`. A field of that type is sealed as the one value that the method
writes. The method writes the value with one of the Encoder's methods,
such as `Int64`, `String`, or `Date`. The Encoder has one method for each
kind of scalar. `Encoder.Err` returns the first error of the encode.

The zero Encoder keeps nothing and does not panic. The `Err` method of
the zero Encoder returns an error that says so. A unit test of your type
can therefore pass the zero Encoder to `EncryptValue`.

- `Diagnostic.Row` and `Diagnostic.Found` (#1985). The two accessors give
more detail for an error about a plan, a record, or a stored row that is
Expand All @@ -37,6 +50,46 @@ and `languages/golang/encrypt/encrypttest/vX.Y.Z` on the same commit.

### Breaking

- **`encrypt.Date`, `Decimal`, `Int128`, and `Uint128` are now types of
this package.** Each was an alias of a Go value type of vitaminc, in
`github.com/cipherstash/vitaminc/bindings/go/vcvalue`. The stored format
is unchanged: every value has the same ciphertext and the same terms as
before.

These things stay the same:

- The types have the same fields, and the same methods except the two
that are removed.
- `ParseInt128`, `ParseUint128`, and `ParseDecimal` accept the same text
and refuse the same text.
- `errors.Is(err, encrypt.ErrNonFiniteDecimal)` matches as before.

These things change for every program:

- `Date.DaysFromCE` and `Decimal.Normalized` are removed.
- The text of an error from a parse function or from `Validate` now
starts with "encrypt: ".
- `ErrNonFiniteDecimal` is a new error value of this package.

These things change only for code that names a `vcvalue` or `vcffi`
type:

- Replace `vcvalue.Date`, `Decimal`, `Int128`, `Uint128`, or `UUID` with
the `encrypt` type of the same name.
- Change a method `EncryptValue(enc vcffi.Encoder) error` to take an
`encrypt.Encoder`. The unsigned methods of an `encrypt.Encoder` are
named `Uint8` to `Uint128`, not `UInt8`. An `encrypt.Encoder` writes
scalars only.
- Remove `vcffi.FixedWidth`. That interface no longer exists. A nil
pointer to an `Encryptable` is written as a null. The engine pads a
sealed null to the width of the type that the field declares, as it
does for every null.

A field that declares no type has no width to pad to. The length of
the stored null would then show that it is a null. `Cipher.Seal`
therefore refuses a nil `Encryptable` for such a field, with
`ErrEncoding`. Generated code always declares a type.

- **`Match` refuses `vars` that are not a JSON object with the reason
`json_vars_not_object`, not `json_input`** (#1987). If your program
compares `Reason()` with `json_input` for this case, change it to the
Expand All @@ -49,6 +102,18 @@ and `languages/golang/encrypt/encrypttest/vX.Y.Z` on the same commit.

### Changed

- **The module no longer depends on vitaminc's Go packages.** The module
used two things from vitaminc's `vcffi` and `vcvalue` packages. The
first is the frame codec, the code that encodes a value to send it to
the engine. The second is the storage profile, the format in which an
opaque struct is stored. Both are now in this module, in
`internal/frame`.

`go.mod` therefore names no vitaminc module, so a final version of the
module can be released. The codec writes the same bytes as before. The
tests of the codec read the same value corpus and storage corpus as the
Rust codec, from this repository.

- **A decrypt error names the field and the Go type that the field
needs, and never the kind that the value decrypted to** (#1987). The Go
type, the kind, and the length of a decrypted value were inside the
Expand Down
13 changes: 6 additions & 7 deletions languages/golang/auth/answer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"strings"
"testing"

"github.com/cipherstash/vitaminc/bindings/go/vcffi"
"github.com/cipherstash/vitaminc/bindings/go/vcvalue"
"github.com/cipherstash/stack/languages/golang/internal/frame"
)

// When the answer of an auth guest is not an object, the error is
Expand All @@ -22,7 +21,7 @@ func TestAnAnswerThatIsNotAnObjectNamesTheExportAndItsKind(t *testing.T) {
{"secret-token", "a string"},
{[]byte("secret-key"), "bytes"},
} {
encoded, err := vcffi.Marshal(tc.answer)
encoded, err := frame.Marshal(tc.answer)
if err != nil {
t.Fatal(err)
}
Expand All @@ -38,7 +37,7 @@ func TestAnAnswerThatIsNotAnObjectNamesTheExportAndItsKind(t *testing.T) {
t.Errorf("the error holds the answer: %v", err)
}
}
encoded, err := vcffi.Marshal(vcvalue.Object{{Key: "access_token", Value: "t"}})
encoded, err := frame.Marshal(frame.Object{{Key: "access_token", Value: "t"}})
if err != nil {
t.Fatal(err)
}
Expand All @@ -58,7 +57,7 @@ func TestAnAnswerThatIsNotAnObjectNamesTheExportAndItsKind(t *testing.T) {
// value that the answer is.
func TestListAnswersNameTheExportAndTheirKind(t *testing.T) {
marshal := func(v any) []byte {
out, err := vcffi.Marshal(v)
out, err := frame.Marshal(v)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -95,7 +94,7 @@ func TestListAnswersNameTheExportAndTheirKind(t *testing.T) {
// contains the value of the field, because the value can be a token or a
// key.
func TestAnAnswersFieldsNameTheExport(t *testing.T) {
answer := fields{export: "sa_token", obj: vcvalue.Object{
answer := fields{export: "sa_token", obj: frame.Object{
{Key: "access_token", Value: int64(7)},
{Key: "client_key", Value: "secret-key"},
{Key: "region", Value: []byte("secret")},
Expand Down Expand Up @@ -138,7 +137,7 @@ func TestAStepThatDoesNotReadNamesTheExport(t *testing.T) {

func mustMarshalAuth(t *testing.T, v any) []byte {
t.Helper()
out, err := vcffi.Marshal(v)
out, err := frame.Marshal(v)
if err != nil {
t.Fatal(err)
}
Expand Down
Loading
Loading