Skip to content

Commit c71dcd8

Browse files
committed
refactor(eql): rebuild the v4 migration codec on Stack Encrypt's typed API
The codec went through `eql_bindings::encryption::targets`, the by-name dispatch for bindings that have no Rust type to name. That made it carry a plaintext-kind table, `ValueFrame` conversions, index-key parsing and `Pending::all` over raw bytes. A Rust program can name the types, and with #1587 (owned `EncryptTarget`/`DecryptSource` on every v4 type) and #1588 (`Encryption::context_from`) now on `next`, it uses the path a Rust application migrating its own data would. A legacy value decrypts with its column. One generic `Shim<T>` encrypts it as any v4 type, stored or query, under that column, through `context_from`. Each item's `type` is read into a serde enum, which also types the plaintext, so a plaintext of the wrong kind and an unknown type are refused while the request is read, before any key is requested. serde's own message for a wrong kind quotes the value, so only messages that name nothing but fields and types are passed on. Each list is still one ZeroKMS call, whatever mix of types it holds, because every item maps to a `Pending<Value>` and `Pending::all` merges them. The wire format is unchanged, so `tests/v4-codec.ts` and both migration suites need no change beyond comments. The tests now cover a mixed-type batch (one generate, one retrieve, order kept), a query operand matching its stored value, a payload read under another column, and a payload from another producer refused by name, as the suites' relabel tests expect. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013Q6HAQrFBLJvRQ1y1xmsxv
1 parent 1bcbdd6 commit c71dcd8

2 files changed

Lines changed: 478 additions & 312 deletions

File tree

  • languages/typescript/packages/protect-ffi/integration-tests/tests
  • packages/eql/tests/encryption/examples

‎languages/typescript/packages/protect-ffi/integration-tests/tests/v4-codec.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import type { Client } from 'pg'
77
// only: no TypeScript SDK writes `v: 4` yet. The migration suites
88
// (`migrate-v*-to-v4.test.ts`) therefore decrypt legacy rows here with
99
// protect-ffi and re-encrypt the plaintexts through a small Rust codec,
10-
// `packages/eql/tests/encryption/examples/v4_codec.rs`. It dispatches on the
11-
// EQL type name through `eql_bindings::encryption::targets`, the same entry
12-
// point the Go guest uses, under live ZeroKMS and the same `CS_*` credentials
13-
// as protect-ffi.
10+
// `packages/eql/tests/encryption/examples/v4_codec.rs`. It encrypts each value
11+
// through Stack Encrypt's typed API, under the column the value came from, as
12+
// a Rust application migrating its own data would, over live ZeroKMS and the
13+
// same `CS_*` credentials as protect-ffi. Each request list is one ZeroKMS
14+
// call.
1415
//
1516
// Built by `mise run eql:v4:codec` (part of `mise run setup`), under
1617
// `CARGO_TARGET_DIR` when that is set. Set `EQL_V4_CODEC` to use a binary
@@ -30,7 +31,10 @@ export function codecPathFor(env: NodeJS.ProcessEnv): string {
3031

3132
export const codecPath = codecPathFor(process.env)
3233

33-
/** An EQL v4 type name, e.g. `TextEq`, as `targets::targets()` lists it. */
34+
/**
35+
* An EQL v4 type name, e.g. `TextEq`: one of the variants of the codec's
36+
* `Encrypt` enum. `Query` has no `Boolean`, which answers no query.
37+
*/
3438
export type V4Type =
3539
| 'Boolean'
3640
| 'IntegerOrdOpe'

0 commit comments

Comments
 (0)