From 173b831b4b22fd316e935dc645947298e9bff91e Mon Sep 17 00:00:00 2001 From: Lindsay Holmwood Date: Fri, 27 Nov 2026 01:46:30 +1100 Subject: [PATCH 1/3] docs(golang): say a query through a cipher with a binding is refused The encrypt README said to query a bound value through a cipher with the same scope, and did not say what happens through a cipher with a binding. Readers took that as accepted. Cipher.queryPlan refuses it with ErrEncoding, because a binding is in the stored context only and no query context holds it. The README now says so, and says to query through the scope alone, then open the row through the cipher with the binding. Refs #1862 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk --- languages/golang/CHANGELOG.md | 7 +++++++ languages/golang/encrypt/README.md | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/languages/golang/CHANGELOG.md b/languages/golang/CHANGELOG.md index 6833efd30..af8acacf1 100644 --- a/languages/golang/CHANGELOG.md +++ b/languages/golang/CHANGELOG.md @@ -22,6 +22,13 @@ and `languages/golang/encrypt/encrypttest/vX.Y.Z` on the same commit. `[16]byte` (`github.com/google/uuid.UUID`, say), which is converted to one. `stashgen` does not yet map a Go type to it. +### Fixed + +- The `encrypt` README now says that a query through a cipher with a + binding is refused with `ErrEncoding`. Query through a cipher with the + same scope and no binding, then open the row through the cipher with the + binding. The README said such a query was accepted. + ## [0.1.0-rc.7] - 2026-11-25 ### Upgrading from rc.6 diff --git a/languages/golang/encrypt/README.md b/languages/golang/encrypt/README.md index 6e67a1e8a..da426a9d8 100644 --- a/languages/golang/encrypt/README.md +++ b/languages/golang/encrypt/README.md @@ -749,7 +749,12 @@ The scope and the binding come after the column in the field's context. The EQL value stores the table and the column alone, in `i`, so: - open the value through a cipher with the same scope and binding; -- query it through a cipher with the same scope. A binding is in no query; +- query it through a cipher with the same scope and no binding, such as + `cipher.Scope(tenant)`. A binding is in no query context, so a query + through a cipher with a binding is refused with `ErrEncoding`. The + refusal covers every query method, such as `Eq`, `Matches`, and + `Contains`. The query by the scope alone finds the row. Open the row + it finds through `cipher.Scope(tenant).Bind(rowID)`; - read part of a `JsonSearch` document (`Selector`, `Subtree`, `Children`) through a cipher with the same scope and binding. The selector or the tokens derive under the scope alone, as a query does, and the entries From 2184f2400c8c604cf797d528f520cf459f865722 Mon Sep 17 00:00:00 2001 From: Lindsay Holmwood Date: Fri, 27 Nov 2026 02:10:26 +1100 Subject: [PATCH 2/3] docs(golang): say the stashgen README's bound query is refused too The stashgen README gave cipher.Scope(tenant).Bind(rowID) as its example and then said to query through a cipher with the same scope, with no word about the refusal. Cipher.queryPlan refuses a query through a cipher with a binding with ErrEncoding. The README now says to query through the scope alone, and that the bound query is refused. The CHANGELOG entry now follows the file's form, cites the issue, and no longer says the old README called the query accepted. Refs #1862 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk --- languages/golang/CHANGELOG.md | 9 +++++---- languages/golang/cmd/stashgen/README.md | 6 ++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/languages/golang/CHANGELOG.md b/languages/golang/CHANGELOG.md index af8acacf1..17f3d85bb 100644 --- a/languages/golang/CHANGELOG.md +++ b/languages/golang/CHANGELOG.md @@ -24,10 +24,11 @@ and `languages/golang/encrypt/encrypttest/vX.Y.Z` on the same commit. ### Fixed -- The `encrypt` README now says that a query through a cipher with a - binding is refused with `ErrEncoding`. Query through a cipher with the - same scope and no binding, then open the row through the cipher with the - binding. The README said such a query was accepted. +- **The `encrypt` and `stashgen` READMEs say a query through a cipher with + a binding is refused** (#1862). The refusal is `ErrEncoding`. Query + through a cipher with the same scope and no binding, then open the row + through the cipher with the binding. The READMEs did not say that such a + query is refused. ## [0.1.0-rc.7] - 2026-11-25 diff --git a/languages/golang/cmd/stashgen/README.md b/languages/golang/cmd/stashgen/README.md index 5c4b1800a..4a18b5b70 100644 --- a/languages/golang/cmd/stashgen/README.md +++ b/languages/golang/cmd/stashgen/README.md @@ -443,8 +443,10 @@ Put the column on the left of `@@` (`WHERE name @@ $1::eql_v4.query_text_match`) `encrypt_into` with any other type is refused with the type's name and the reason it is not produced yet. Separate columns work today for four indexes: `equality`, `match`, `ore` and `ope`. -A field with `encrypt_into` is stored under its table and column, which is what an EQL value records in its `i`. -A cipher with a scope or a binding (`cipher.Scope(tenant).Bind(rowID)`) seals a struct with an `encrypt_into` field as it seals any other. The scope and the binding come after the column in the field's context, and `i` still holds the table and the column alone. Open the value through a cipher with the same scope and binding, and query it through a cipher with the same scope. +A field with `encrypt_into` is stored under its table and column. An EQL value records them in its `i`. +A cipher with a scope or a binding (`cipher.Scope(tenant).Bind(rowID)`) seals a struct with an `encrypt_into` field as it seals any other. The scope and the binding come after the column in the field's context, and `i` still contains the table and the column alone. + +Open the value through a cipher with the same scope and binding. Query it through a cipher with the same scope and no binding, such as `cipher.Scope(tenant)`. A query through a cipher with a binding is refused with `ErrEncoding`, because a binding is in no query context. ## When stashgen stops From d15d240b222d3c0a2d0037fb3815d88aabdea854 Mon Sep 17 00:00:00 2001 From: Lindsay Holmwood Date: Fri, 27 Nov 2026 15:31:21 +1100 Subject: [PATCH 3/3] docs(golang): say the context binds bindings, and name Bind as a way to tie a value to its row The Take care note in the encrypt README said the context binds a value to its table, its column and the cipher's extension, and offered only a context_field to tie a value to its row. The context also binds any bindings, and cipher.Scope(tenant).Bind(rowID) ties a value to its row ID. The note now names both ways, and the trade-off: a cipher with a binding cannot query, and a context_field can query within one context. It also says that a context_field ties a value to its row's context, so a value copied to another row with the same context decrypts there. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CtEQzxj55RUn35dkbhdwQk --- languages/golang/CHANGELOG.md | 6 +++++ languages/golang/encrypt/README.md | 41 +++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/languages/golang/CHANGELOG.md b/languages/golang/CHANGELOG.md index 17f3d85bb..edd4b5c8b 100644 --- a/languages/golang/CHANGELOG.md +++ b/languages/golang/CHANGELOG.md @@ -29,6 +29,12 @@ and `languages/golang/encrypt/encrypttest/vX.Y.Z` on the same commit. through a cipher with the same scope and no binding, then open the row through the cipher with the binding. The READMEs did not say that such a query is refused. +- **The `encrypt` README's note on the context names bindings** (#1862). + The context binds each value to its scopes and any bindings too. The + note now gives `cipher.Scope(tenant).Bind(rowID)` as a way to tie a + value to its row. A cipher with a binding cannot query. The note also + keeps the `context_field` way. A `context_field` can query within one + context. Before, the note offered only the `context_field`. ## [0.1.0-rc.7] - 2026-11-25 diff --git a/languages/golang/encrypt/README.md b/languages/golang/encrypt/README.md index da426a9d8..5fbcb131a 100644 --- a/languages/golang/encrypt/README.md +++ b/languages/golang/encrypt/README.md @@ -214,11 +214,24 @@ cannot use different ones. > **Take care** > -> The context binds each value to its table, its column and the cipher's -> extension. It does not bind the value to its row, so a value copied to -> another row of the same table decrypts there with no error. To bind each -> row to a context of its own, such as its tenant, give the struct a -> `context_field` instead of a `context=` tag: +> The context binds each value to its table, its column, the cipher's +> scopes, and any bindings. Without a binding or a `context_field`, a value +> copied to another row of the same table decrypts there with no error. +> There are two ways to tie a value to its row. +> +> **Bind the value to its row ID.** Encrypt and decrypt through +> `cipher.Scope(tenant).Bind(rowID)`. A value sealed this way opens only +> through a cipher with the same scope and binding. A value copied to +> another row does not open under that row's ID. +> +> A cipher with a binding cannot query: every query method refuses it with +> `ErrEncoding`. Query through `cipher.Scope(tenant)`, then open each row it +> finds through the cipher with that row's binding. +> +> **Give the struct a `context_field`** instead of a `context=` tag. The +> field stays queryable, within one context. The value is tied to the +> context its row stores, such as its tenant, rather than to the row +> itself: > > ```go > type Note struct { @@ -228,16 +241,20 @@ cannot use different ones. > ``` > > The field's value is the context every other field is sealed under, a -> label such as `"tenants/acme"`. It is stored as it is, in the clear and -> unauthenticated like a passthrough field, so the row names its own -> context. A row's sealed values open only under the context the row +> label such as `"tenants/acme"`. The field is stored as it is, in the +> clear and unauthenticated like a passthrough field, so the row names its +> own context. A row's sealed values open only under the context the row > stores: a value copied to another tenant's row does not decrypt there. +> A value copied to another row with the same context does decrypt there. +> > `Encrypt` and `Decrypt` take each row's context from the row. > `cipher.Context("tenants/acme")` names the context every row through the -> cipher is under: `Decrypt` then refuses a row stored under another tenant -> with `ErrContextMismatch`, before any key is retrieved, and `Encrypt` -> refuses a value whose field says otherwise. A query on such a type derives -> its term under the context the cipher names, and fails without one. +> cipher is under. `Decrypt` then refuses a row stored under another tenant +> with `ErrContextMismatch`, before any key is retrieved. `Encrypt` refuses +> a value whose field says otherwise. +> +> A query on such a type derives its term under the context the cipher +> names, and fails without one. So a query through `cipher.Context("tenants/acme")` finds that tenant's rows. `Client.DefaultKeyset()` is the keyset a ZeroKMS administrator set for the client; `Client.Keyset(encrypt.KeysetName(..))` or `Client.Keyset(id)` any