Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions languages/golang/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ and `languages/golang/encrypt/encrypttest/vX.Y.Z` on the same commit.

## [Unreleased]

### Fixed

- **The docs name the types that implement `driver.Valuer`** (#1861). They
said every stored type does. The struct that stashgen writes for a field
with `encrypt` or `index=`, such as `EncryptedUserEmail`, does not. Bind
and scan each of its fields as its own column. The docs also said every
query type implements `driver.Valuer`. A `Range` does not: it binds as two
parameters.

## [0.1.0-rc.7] - 2026-11-25

### Upgrading from rc.6
Expand Down
1 change: 1 addition & 0 deletions languages/golang/cmd/stashgen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ For `-type User`, the file `user_stash.go` holds:
A passthrough field keeps its Go type.
A field with `encrypt_into` holds one EQL value.
A field with `encrypt` or `index=` holds a struct with one field for each output, such as `Email.Ciphertext` and `Email.Equality`.
That struct is not a `driver.Valuer` or an `sql.Scanner`. Bind and scan each of its fields as its own column. The types of its fields, `encrypt.Ciphertext` and the term types, implement `driver.Valuer`, and a pointer to each implements `sql.Scanner`.
- `Encrypt` and `Decrypt`, which take a slice and return a slice, and send one ZeroKMS request for each 500 sealed values in it, plus one the first time a keyset is used.
- `Fields`, with one entry for each sealed field.
An opaque struct, or a struct with no sealed field outside an opaque one, gets no `Fields`: nothing in it is sealed on its own, so nothing can be queried.
Expand Down
19 changes: 15 additions & 4 deletions languages/golang/encrypt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,17 @@ A field with `encrypt` and `index=` is a struct with one field for each
output: `Ciphertext` (`encrypt.Ciphertext`, the frozen stack-encrypt leaf),
and `Equality`, `Match`, `Ore` or `Ope` (the term types). A field with
`encrypt` alone has `Ciphertext` only. A passthrough field keeps its Go type.
An `opaque` struct is one `Sealed` field. Every stored type implements
`driver.Valuer` and `sql.Scanner`.
An `opaque` struct is one `Sealed` field, an `encrypt.Ciphertext`.

Each stored value is one column. `encrypt.Ciphertext`, the term types and
every value and query type in `encrypt/eql` implement `driver.Valuer`, and
a pointer to each implements `sql.Scanner`. So a database library binds
each one, and scans into its address (`rows.Scan(&e.Email.Ciphertext)`).

The struct that contains a field's outputs, such as `EncryptedUserEmail`,
implements neither interface. Bind and scan each of its fields as its own
column: `Email.Ciphertext`, `Email.Equality`. A passthrough field
implements them only when its own Go type does.

A sealed field outside an opaque struct is one value of one of these types,
or a type defined over one (`type Email string`):
Expand Down Expand Up @@ -471,8 +480,10 @@ bytes, so the term would be stored, where anyone who reads the column can
compare it, and no query could use it. A match index on an index-only field (`index=match` with no `encrypt`)
is refused, because `Verify` checks a match query's rows by decrypting them.

Every query type implements `driver.Valuer`, so it binds as a parameter in
any library built on `database/sql` or pgx. A `Range` binds as two
`encrypt.EqualityTerm`, `encrypt.OreTerm`, `encrypt.OpeTerm`,
`encrypt.MatchQuery`, `encrypt.EQLMatchQuery` and every query type in
`encrypt/eql` implement `driver.Valuer`. Each binds as one parameter in any
library built on `database/sql` or pgx. A `Range` does not: it binds as two
parameters, `Low` and `High`. On an EQL column a range is one value instead:
package `encrypt/eql` has a range query type per ordered family and order
index (`eql.IntegerRangeOreQuery`, `eql.TextRangeOpeQuery`, ...), the one
Expand Down
17 changes: 14 additions & 3 deletions languages/golang/encrypt/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,16 @@
// the Rust crate derives, so a term from a generated Fields entry compares
// against a stored term from any language. The indexes are [Equality],
// [Match], [Ore] and [Ope]; [JSON] is declared and refused until the engine
// derives it. Every stored type implements driver.Valuer and sql.Scanner.
// derives it.
//
// Each stored value is one column. [Ciphertext], the term types and every
// value and query type in package eql implement driver.Valuer, and a
// pointer to each implements sql.Scanner. So a database library binds each
// one, and scans into its address. The struct that generated code
// writes for a field's outputs (EncryptedUserEmail, with Ciphertext and
// Equality fields) implements neither. Bind and scan each of its fields as
// its own column. A passthrough field implements them only when its own Go
// type does.
//
// A match index stores text with no token (an empty string, separator-only
// text, or text shorter than the n-gram length of 3 characters) as the empty
Expand Down Expand Up @@ -178,8 +187,10 @@
// [MatchQuery.Verify] reports true, one call into the engine for the page.
// On a field with encrypt_into=TextMatch, Matches returns an
// [EQLMatchQuery], the type's query value with the same two methods.
// Every query type implements driver.Valuer, so it binds as a parameter
// through database/sql or pgx. With separate byte columns, as the example/
// [EqualityTerm], [OreTerm], [OpeTerm], [MatchQuery], [EQLMatchQuery] and
// every query type in package eql implement driver.Valuer. Each binds as
// one parameter through database/sql or pgx. A [Range] does not: bind its
// Low and High as two parameters. With separate byte columns, as the example/
// program declares its fields (Email `stash:"email,encrypt,index=equality;match"`,
// Age `stash:"age,encrypt,index=equality;ore"`), not the encrypt_into User
// above:
Expand Down
7 changes: 4 additions & 3 deletions languages/golang/encrypt/eql/eql.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
// generated encrypted type, and its Fields entry's Eq returns a
// [TextEqQuery]. The guest builds every value: generated code stores what
// the guest returns and never assembles an EQL value itself (ADR-0007,
// amended 2026-10-06). Each type implements driver.Valuer and sql.Scanner
// for one column, and json.Marshaler, which writes the value as the JSON
// it is. It prints (fmt.Stringer, fmt.Formatter, for every verb) and logs
// amended 2026-10-06). Each value and query type implements driver.Valuer
// for one column, and a pointer to it implements sql.Scanner. Each also
// implements json.Marshaler, which writes the value as the JSON it is. It
// prints (fmt.Stringer, fmt.Formatter, for every verb) and logs
// (slog.LogValuer) as its type's name and never its bytes, so fmt.Sprint
// and %s do not give its JSON: a stored value holds ciphertext and terms,
// and a query value terms. To print or log the JSON on purpose, call
Expand Down
Loading