Skip to content
Merged
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 .changeset/eql-bindings-order-queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@cipherstash/eql': minor
---

`eql-bindings`, the Rust crate released with this package: the field reference of an ordered EQL v4 type answers order queries. `EncryptedMember::AGE.gt(30).encrypt(&keyset)` gives the type's query twin (`IntegerOrdQuery`, `DateOrdOreQuery`, …) for `lt`, `lte`, `gt` and `gte` on every `…Ord`, `…OrdOpe` and `…OrdOre` type. `TextOrd`, `TextOrdOpe` and `TextOrdOre` answer `eq` too, and `TextSearch` and `TextSearchOre` answer `eq`, the orderings and `matches`. Each query is the one a data plan derives for a field that names the type.

A `TextOrd*` query carries its `hm` and its order term whatever the operator, and is refused, before any key is requested, for text either index refuses. `between` is not answered from a field reference.

The stored format, the SQL bundle and the TypeScript types do not change.
21 changes: 17 additions & 4 deletions docs/plans/2026-10-24-stack-encrypt-api-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -1587,18 +1587,31 @@ Base64.
`DecryptSource<JsonPlaintext>`.
- A query from a field reference works for the equality and match
types, with the record's scope. A data plan's query for an EQL type
takes a scope too. The order types do not implement `Answers` yet, so
a field reference cannot query them (#1668).
takes a scope too.
- In #1668, a field reference queries the order types too: `lt`, `lte`,
`gt` and `gte` on every ordered type, `eq` as well on `TextOrd`, and
the orderings and `matches` on text search. A twin that requires
several terms (`TextOrdQuery`'s `hm` and `op`) gets all of them for the
one value; a twin whose terms are optional gets the answering index's
term alone, as the data plan's does. No SQL or stored form changes.
Each query is the data plan's for the same value, and each finds the
rows the other finds
(`packages/eql/tests/encryption/tests/typed_queries.rs`,
`typed_order_queries.rs`). A `TextOrd*` query is refused, before any
key is requested, for text either of its indexes refuses, by both
paths. `between` is not answered from a field reference, as the data
plan answers it on no EQL type; #1286 answers it on both.
- A data plan that names an EQL type takes a scope and a binding too.
`TargetResolver` receives them after the field's label, and
`TargetError::Extended` is removed. Under the same scope and binding,
a data plan and a derived record write the same terms, and each
opens the other's values. A Go struct with an `encrypt_into` field
seals through `cipher.Scope(..).Bind(..)`.
- **Tracked in.** Issue #1658 is open. Pull request #1659, open, closes it. Issue #1668 is open for order queries from a field reference. `eql-bindings` builds against the crates.io `stack-encrypt`, so a `stack-encrypt` release with `ContextFromField` must come before the `eql-bindings` release that uses it.
- **Tracked in.** Issue #1658 is closed: pull request #1659 closed it and merged on 2026-11-21. Issue #1668 is for order queries from a field reference, and pull request #1752 closes it. Issue #1286 is for `between` from a field reference and from a data plan. `eql-bindings` builds against the crates.io `stack-encrypt`, so a `stack-encrypt` release with `ContextFromField` must come before the `eql-bindings` release that uses it.
- **Finished when** these are all true:
- a Rust record with EQL fields encrypts, decrypts, and queries through
the new API, including order queries;
the new API, including the order queries `lt`, `lte`, `gt` and `gte`,
and `between` (#1286);
- it writes the same terms as a Go record with the same declaration,
with and without a scope.

Expand Down
4 changes: 4 additions & 0 deletions languages/golang/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ and `languages/golang/encrypt/encrypttest/vX.Y.Z` on the same commit.

### Changed

- An `eq` query on a `TextOrdOre` field of text that ends in NUL, or is too
long for block ORE, is refused before any key is requested, as an
ordering of the same text is (#1668). It was refused with the same error
after the keyset's index key was loaded.
- `Children` through a cipher with a binding now prepares the read, as
`Selector` and `Subtree` do (#1677). Before, the cipher refused it. The
token derives under the cipher's scopes alone. The children open under
Expand Down
33 changes: 33 additions & 0 deletions packages/eql/crates/eql-bindings/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,39 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
the `JsonTreeToken` to send. The call also returns the key that
decrypts what the query returns.
- The stored format and the SQL do not change.
- **Order queries from a field reference** (#1668). The field reference of a
field typed with an ordered EQL v4 type has `lt`, `lte`, `gt` and `gte`:
`EncryptedMember::AGE.gt(30).encrypt(&keyset)` returns the type's query
twin (`IntegerOrdQuery`, `DateOrdOreQuery`, …). This covers every
producible `…Ord`, `…OrdOpe` and `…OrdOre` type. `TextOrd`, `TextOrdOpe`
and `TextOrdOre` answer `eq` too. `TextSearch` and `TextSearchOre` answer
`eq`, the orderings and `matches`. Each query is the one a data plan
derives for a field that names the type, for the same operator and value,
and binds as the twin's query domain. A block ORE term carries a random
nonce, so its bytes differ between derivations, and it compares equal.
- A twin that requires several terms carries all of them whatever the
operator: a `TextOrd` query derives both its `hm` and its `op` for the
one value, since `eql_v4.query_text_ord` requires both. A text search
twin's terms are optional, so its query carries only the term of the
index that answers the operator. No EQL SQL and no stored form changes.
- `TwinIndex` takes a third type parameter, the indexes whose terms the
twin carries. It defaults to the answering index, so
`TwinIndex<Equality, TextEqQuery>` is unchanged. `TextOrd` answers
`op::Lt` through `TwinIndex<Ope, TextOrdQuery, (Equality, Ope)>`.
- `QueryTwin<T>` is implemented for an order term (`OpeTerm<S>`,
`OreBlockTerm<S>`), for a pair `(Hmac256, OpeTerm<String>)` or
`(Hmac256, OreBlockTerm<String>)`, and, for a twin whose terms are
optional, once per term.
- A query on a twin that carries an order term beside its `hm` is
refused, before any key is requested, for what either index refuses:
`TextOrdOre` `eq` of text that ends in NUL or is too long for block ORE
is refused as an ordering of it is. The descriptor `EqlTargets` gives
Stack Encrypt says which types' twins carry every term
(`Target::query_carries_every_term`), so a data plan refuses the same
queries at the same point.
- A field reference has no `between` yet. A range query sends both
bounds in one operand, and no SDK builds that operand. A data plan
refuses `between` on an EQL type for the same reason. #1286 tracks it.

- **A `JsonTreeDocument` field is queried from its field reference** (#1459,
#1687). As a field of a derived record, a `JsonTreeDocument` (and an
Expand Down
29 changes: 24 additions & 5 deletions packages/eql/crates/eql-bindings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,18 +429,30 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
| `SmallintEq`, `IntegerEq`, `BigintEq`, `RealEq`, `DoubleEq` | `eq` | `op::Eq` | `SmallintEqQuery`, `IntegerEqQuery`, `BigintEqQuery`, `RealEqQuery`, `DoubleEqQuery` |
| `DateEq`, `TimestampEq`, `NumericEq` | `eq` | `op::Eq` | `DateEqQuery`, `TimestampEqQuery`, `NumericEqQuery` (from `v4::plaintext::Date`, `Timestamp`, `Decimal`) |
| `TextMatch` | `matches` | `op::Matches` | `MatchTwin<TextMatchQuery>` |
| `SmallintOrd`, `IntegerOrd`, `BigintOrd`, `RealOrd`, `DoubleOrd`, `DateOrd`, `TimestampOrd`, `NumericOrd`, and each `…OrdOpe` and `…OrdOre` | `lt`, `lte`, `gt`, `gte` | `op::Lt`, `op::Lte`, `op::Gt`, `op::Gte` | the type's twin: `IntegerOrdQuery`, `IntegerOrdOreQuery`, … |
| `TextOrd`, `TextOrdOpe`, `TextOrdOre` | `eq`, `lt`, `lte`, `gt`, `gte` | `op::Eq` and the orderings | `TextOrdQuery`, `TextOrdOpeQuery`, `TextOrdOreQuery` |
| `TextSearch`, `TextSearchOre` | `eq`, `lt`, `lte`, `gt`, `gte`, `matches` | `op::Eq`, the orderings and `op::Matches` | `TextSearchQuery`, `TextSearchOreQuery`, and a `MatchTwin` of one for `matches` |

`MatchTwin` serializes as the twin and adds `verify` and `target_limit`
under `EqlMatch`: a filter can match a row that does not hold the query's
text, so keep only the decrypted rows that verify. An exact query has no
`verify`. An operator a type does not answer does not compile: `.lt(..)` on
a `TextEq` field, or `.matches(..)` on an `IntegerEq` field. A field reference names
its field's type and no index, so a query cannot send another index's term,
such as the bare `Equality` term, which the type's SQL does not take. The
ordered types (`IntegerOrd`, `TextOrd`, …) and the text search types answer
nothing from a field reference yet: their twins need an order term, or several terms
at once, and a field query sends one index's term. Query them through
the data path (`stack_encrypt::dynamic::query_term`) for now.
such as the bare `Equality` term, which the type's SQL does not take. No
type answers `between` from a field reference, as no data plan answers it
for an EQL type.

A twin carries what its query domain requires. The twin of an ordered
type other than text carries its one order term (`op` or `ob`). A
`TextOrd` twin carries both its `hm` and its order term whatever the
operator, because `eql_v4.query_text_ord` requires both, so a field query
derives the two terms for the one value. It is refused, before any key is
requested, for text either index refuses: `TextOrdOre.eq(..)` of text that
ends in NUL or is too long for block ORE, as the data path refuses it. A
text search twin's terms are optional, so its query carries only the term
of the index that answers the operator: `hm` for `eq`, `op` or `ob` for an
ordering, `bf` for `matches`.

The query is derived under the field reference's label: the record's scope, then the
field's name (or its `identity`). That is the column the field stores in
Expand Down Expand Up @@ -542,6 +554,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.await?;
assert_eq!(query.hm, stored.email.hm);

// An order query: an `IntegerOrdQuery`, bound as
// WHERE age > $1::eql_v4.query_integer_ord.
let older = EncryptedMember::AGE.gt(30).encrypt(&keyset).await?;
assert_eq!(older.i, stored.age.i);
// Its order term sorts below the stored age of 36.
assert!(older.op < stored.age.op);

let opened = Member::decrypt_from(stored, &keyset).await?;
assert_eq!(opened.email, "alice@example.com");
Ok(())
Expand Down
Loading
Loading