Skip to content

Commit 7c8e018

Browse files
committed
refactor(eql-bindings): compile eql_bindings::v4 only with the stack-encrypt feature
Only Stack Encrypt produces an EQL v4 value, yet the v4 module compiled without the feature and every generated derive, stash attribute and doc line was wrapped in its own cfg_attr on it. The module itself is now gated in lib.rs, and eql-codegen emits the v4 derives and docs unconditionally. v4_parity.rs runs under the feature, where test:encryption runs it. The Go docs listing what encrypt_into takes (encrypt/doc.go and the stashgen README) now name the four number equality types, and say which types answer Eq and which are stored and read only. Claude-Session: https://claude.ai/code/session_01BZhkvKLpNtKuzj3HCfMXoL
1 parent 7f8cb75 commit 7c8e018

15 files changed

Lines changed: 191 additions & 468 deletions

File tree

‎.changeset/eql-v4-bindings.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
'@cipherstash/eql': minor
33
---
44

5-
**The `eql-bindings` crate has an `eql_bindings::v4` module: payload types for the EQL v4 domains.** EQL v4 is the v3 SQL installed under a second name (ADR-0002), for values written by Stack Encrypt. The module is generated from the same catalog as `v3`, with `eql_v4_*` domain names and `"v": 4`. `SchemaVersion` is now generic over the version it admits: `v3::SchemaVersion` is `SchemaVersion<3>` and `v4::SchemaVersion` is `SchemaVersion<4>`, each refusing the other's payloads, and plain `SchemaVersion` still means v3. Only v4 types derive Stack Encrypt's `EncryptFrom` and `DecryptInto`, and the Stack Encrypt target table (now `eql_bindings::v4::targets`) names v4 domains. Besides `TextEq`, Stack Encrypt now produces the storage-only types `Text`, `Integer`, `Bigint`, `Boolean`, `Real` and `Double`, and `TextMatch` (3-grams, `k = 6`, a 2048-bit filter, pinned as `eql_bindings::encryption::EqlMatch`; text shorter than three characters is refused, stored or queried, and only `stored @@ query` matches until #1171 is fixed), from the plaintext types in `eql_bindings::encryption::plaintext`; the Go SDK's `encrypt/eql` table marks them producible. Stack Encrypt also produces the number equality types `IntegerEq`, `BigintEq`, `RealEq` and `DoubleEq`, whose `=` compares as PostgreSQL compares the plain types: an integer has one term whatever its width, and for floats `-0.0 = 0.0` and `NaN = NaN` (ADR-0002's semantic baseline). Every type it cannot produce yet names the issue that tracks its blocker.
5+
**The `eql-bindings` crate has an `eql_bindings::v4` module, with the `stack-encrypt` feature: payload types for the EQL v4 domains.** EQL v4 is the v3 SQL installed under a second name (ADR-0002), for values written by Stack Encrypt, so the module exists only with that feature and its types derive Stack Encrypt's traits without a further gate. The module is generated from the same catalog as `v3`, with `eql_v4_*` domain names and `"v": 4`. `SchemaVersion` is now generic over the version it admits: `v3::SchemaVersion` is `SchemaVersion<3>` and `v4::SchemaVersion` is `SchemaVersion<4>`, each refusing the other's payloads, and plain `SchemaVersion` still means v3. Only v4 types derive Stack Encrypt's `EncryptFrom` and `DecryptInto`, and the Stack Encrypt target table (now `eql_bindings::v4::targets`) names v4 domains. Besides `TextEq`, Stack Encrypt now produces the storage-only types `Text`, `Integer`, `Bigint`, `Boolean`, `Real` and `Double`, and `TextMatch` (3-grams, `k = 6`, a 2048-bit filter, pinned as `eql_bindings::encryption::EqlMatch`; text shorter than three characters is refused, stored or queried, and only `stored @@ query` matches until #1171 is fixed), from the plaintext types in `eql_bindings::encryption::plaintext`; the Go SDK's `encrypt/eql` table marks them producible. Stack Encrypt also produces the number equality types `IntegerEq`, `BigintEq`, `RealEq` and `DoubleEq`, whose `=` compares as PostgreSQL compares the plain types: an integer has one term whatever its width, and for floats `-0.0 = 0.0` and `NaN = NaN` (ADR-0002's semantic baseline). Every type it cannot produce yet names the issue that tracks its blocker.
66

77
Nothing a released version shipped has changed. The v3 types, the v3 SQL and the TypeScript package are as they were; the `stack-encrypt` derives on the v3 text types and the `v3::targets` module were added after the last release and are moved to v4 here, not removed from a release.

‎languages/golang/cmd/stashgen/README.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,13 @@ The engine produces these EQL types today, each from one Go field type:
159159
| `encrypt_into` | Go field |
160160
|---|---|
161161
| `TextEq`, `Text`, `TextMatch` | `string` |
162-
| `Integer` | `int32` |
163-
| `Bigint` | `int64` |
162+
| `Integer`, `IntegerEq` | `int32` |
163+
| `Bigint`, `BigintEq` | `int64` |
164164
| `Boolean` | `bool` |
165-
| `Real` | `float32` |
166-
| `Double` | `float64` |
165+
| `Real`, `RealEq` | `float32` |
166+
| `Double`, `DoubleEq` | `float64` |
167+
168+
The `Eq` types answer `Eq`; `Text`, `Integer`, `Bigint`, `Boolean`, `Real` and `Double` are stored and read only, with no query method.
167169

168170
The width must match: an `int` or `int64` field is not an `Integer`, and a `float64` field is not a `Real`.
169171
A `TextMatch` field refuses text shorter than three characters, such as an empty string or a two-letter code, because it has no 3-grams to index; its query refuses such text too.

‎languages/golang/encrypt/doc.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
// }
2222
//
2323
// encrypt_into names the EQL type the field is stored as. The Go field type
24-
// must match it: TextEq, TextMatch and Text take a string, Integer an int32,
25-
// Bigint an int64, Boolean a bool, Real a float32 and Double a float64.
24+
// must match it: TextEq, TextMatch and Text take a string, Integer and
25+
// IntegerEq an int32, Bigint and BigintEq an int64, Boolean a bool, Real and
26+
// RealEq a float32, and Double and DoubleEq a float64. The *Eq types answer
27+
// Eq; Integer, Bigint, Boolean, Real, Double and Text are stored and read
28+
// only.
2629
//
2730
// 3. Run the generator. It writes user_stash.go beside the struct:
2831
//

‎packages/eql/crates/eql-bindings/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- **`eql_bindings::v4` needs the `stack-encrypt` feature.** Only Stack
13+
Encrypt produces an EQL v4 value (ADR-0002), so the module is compiled with
14+
that feature alone, and its producible types derive `EncryptFrom` and
15+
`DecryptInto` with no attribute of their own gated on it.
1216
- **`IntegerEq`, `BigintEq`, `RealEq` and `DoubleEq` are producible**
1317
(`stack-encrypt` feature), from the `Int32`, `Int64`, `Float32` and
1418
`Float64` plaintexts. Their equality term follows ADR-0002's semantic

‎packages/eql/crates/eql-bindings/src/lib.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ use ts_rs::TS;
4444
pub mod from_v2;
4545
pub mod sql;
4646
pub mod v3;
47+
// EQL v4 holds the payloads Stack Encrypt writes (ADR-0002). Only Stack
48+
// Encrypt produces a v4 value, so the module exists only with the
49+
// `stack-encrypt` feature, and its types derive Stack Encrypt's traits
50+
// unconditionally. (A `///` doc here would move `v4`'s own intra-doc links
51+
// out of its scope.)
52+
#[cfg(feature = "stack-encrypt")]
4753
pub mod v4;
4854

4955
#[cfg(feature = "stack-encrypt")]

‎packages/eql/crates/eql-bindings/src/v4/bigint.rs‎

Lines changed: 24 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,18 @@ use ts_rs::TS;
1414
doc,
1515
doc = " See the [EQL bigint reference](https://cipherstash.com/docs/reference/eql/numbers) for SQL domain variants, operators, and query examples."
1616
)]
17-
#[cfg_attr(doc, doc = "")]
18-
#[cfg_attr(
19-
all(doc, feature = "stack-encrypt"),
20-
doc = " Plaintext input and decrypted output: [`Int64`](crate::encryption::plaintext::Int64). With the `stack-encrypt` feature, implements `EncryptFrom<Int64>` and `DecryptInto<Int64>`."
21-
)]
22-
#[cfg_attr(
23-
all(doc, not(feature = "stack-encrypt")),
24-
doc = " Plaintext input and decrypted output: `Int64`. With the `stack-encrypt` feature, implements `EncryptFrom<Int64>` and `DecryptInto<Int64>`."
25-
)]
26-
#[cfg_attr(
27-
all(doc, feature = "stack-encrypt"),
28-
doc = " Encryption context: `NonEmpty<Identifier>`, constructed with `Identifier::for_column(table, column)` and stored in `i`."
29-
)]
30-
#[cfg_attr(
31-
all(doc, feature = "stack-encrypt"),
32-
doc = " See the [complete encryption example](crate::encryption#example)."
33-
)]
34-
#[cfg_attr(feature = "stack-encrypt", derive(stack_encrypt::EncryptFrom))]
35-
#[cfg_attr(feature = "stack-encrypt", derive(stack_encrypt::DecryptInto))]
36-
#[cfg_attr(
37-
feature = "stack-encrypt",
38-
stash(plaintext = crate::encryption::plaintext::Int64)
39-
)]
17+
///
18+
/// Plaintext input and decrypted output: [`Int64`](crate::encryption::plaintext::Int64). Implements `EncryptFrom<Int64>` and `DecryptInto<Int64>`.
19+
/// Encryption context: `NonEmpty<Identifier>`, constructed with `Identifier::for_column(table, column)` and stored in `i`.
20+
/// See the [complete encryption example](crate::encryption#example).
21+
#[derive(stack_encrypt::EncryptFrom, stack_encrypt::DecryptInto)]
22+
#[stash(plaintext = crate::encryption::plaintext::Int64)]
4023
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TS, JsonSchema)]
4124
#[serde(deny_unknown_fields)]
4225
pub struct Bigint {
43-
#[cfg_attr(feature = "stack-encrypt", stash(default))]
26+
#[stash(default)]
4427
pub v: SchemaVersion,
45-
#[cfg_attr(feature = "stack-encrypt", stash(context_field))]
28+
#[stash(context_field)]
4629
pub i: Identifier,
4730
pub c: Ciphertext,
4831
}
@@ -80,35 +63,18 @@ impl DomainType for Bigint {
8063
doc,
8164
doc = " See the [EQL bigint reference](https://cipherstash.com/docs/reference/eql/numbers) for SQL domain variants, operators, and query examples."
8265
)]
83-
#[cfg_attr(doc, doc = "")]
84-
#[cfg_attr(
85-
all(doc, feature = "stack-encrypt"),
86-
doc = " Plaintext input and decrypted output: [`Int64`](crate::encryption::plaintext::Int64). With the `stack-encrypt` feature, implements `EncryptFrom<Int64>` and `DecryptInto<Int64>`."
87-
)]
88-
#[cfg_attr(
89-
all(doc, not(feature = "stack-encrypt")),
90-
doc = " Plaintext input and decrypted output: `Int64`. With the `stack-encrypt` feature, implements `EncryptFrom<Int64>` and `DecryptInto<Int64>`."
91-
)]
92-
#[cfg_attr(
93-
all(doc, feature = "stack-encrypt"),
94-
doc = " Encryption context: `NonEmpty<Identifier>`, constructed with `Identifier::for_column(table, column)` and stored in `i`."
95-
)]
96-
#[cfg_attr(
97-
all(doc, feature = "stack-encrypt"),
98-
doc = " See the [complete encryption example](crate::encryption#example)."
99-
)]
100-
#[cfg_attr(feature = "stack-encrypt", derive(stack_encrypt::EncryptFrom))]
101-
#[cfg_attr(feature = "stack-encrypt", derive(stack_encrypt::DecryptInto))]
102-
#[cfg_attr(
103-
feature = "stack-encrypt",
104-
stash(plaintext = crate::encryption::plaintext::Int64)
105-
)]
66+
///
67+
/// Plaintext input and decrypted output: [`Int64`](crate::encryption::plaintext::Int64). Implements `EncryptFrom<Int64>` and `DecryptInto<Int64>`.
68+
/// Encryption context: `NonEmpty<Identifier>`, constructed with `Identifier::for_column(table, column)` and stored in `i`.
69+
/// See the [complete encryption example](crate::encryption#example).
70+
#[derive(stack_encrypt::EncryptFrom, stack_encrypt::DecryptInto)]
71+
#[stash(plaintext = crate::encryption::plaintext::Int64)]
10672
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TS, JsonSchema)]
10773
#[serde(deny_unknown_fields)]
10874
pub struct BigintEq {
109-
#[cfg_attr(feature = "stack-encrypt", stash(default))]
75+
#[stash(default)]
11076
pub v: SchemaVersion,
111-
#[cfg_attr(feature = "stack-encrypt", stash(context_field))]
77+
#[stash(context_field)]
11278
pub i: Identifier,
11379
pub c: Ciphertext,
11480
pub hm: Hmac256,
@@ -273,34 +239,18 @@ impl DomainType for BigintOrdOpe {
273239
doc,
274240
doc = " See the [EQL bigint reference](https://cipherstash.com/docs/reference/eql/numbers) for SQL domain variants, operators, and query examples."
275241
)]
276-
#[cfg_attr(doc, doc = "")]
277-
#[cfg_attr(
278-
all(doc, feature = "stack-encrypt"),
279-
doc = " Plaintext input: [`Int64`](crate::encryption::plaintext::Int64). With the `stack-encrypt` feature, implements `EncryptFrom<Int64>` to build equality query terms. Query operands do not decrypt."
280-
)]
281-
#[cfg_attr(
282-
all(doc, not(feature = "stack-encrypt")),
283-
doc = " Plaintext input: `Int64`. With the `stack-encrypt` feature, implements `EncryptFrom<Int64>` to build equality query terms. Query operands do not decrypt."
284-
)]
285-
#[cfg_attr(
286-
all(doc, feature = "stack-encrypt"),
287-
doc = " Encryption context: `NonEmpty<Identifier>`, constructed with `Identifier::for_column(table, column)` and stored in `i`."
288-
)]
289-
#[cfg_attr(
290-
all(doc, feature = "stack-encrypt"),
291-
doc = " See the [complete encryption example](crate::encryption#example)."
292-
)]
293-
#[cfg_attr(feature = "stack-encrypt", derive(stack_encrypt::EncryptFrom))]
294-
#[cfg_attr(
295-
feature = "stack-encrypt",
296-
stash(plaintext = crate::encryption::plaintext::Int64)
297-
)]
242+
///
243+
/// Plaintext input: [`Int64`](crate::encryption::plaintext::Int64). Implements `EncryptFrom<Int64>` to build equality query terms. Query operands do not decrypt.
244+
/// Encryption context: `NonEmpty<Identifier>`, constructed with `Identifier::for_column(table, column)` and stored in `i`.
245+
/// See the [complete encryption example](crate::encryption#example).
246+
#[derive(stack_encrypt::EncryptFrom)]
247+
#[stash(plaintext = crate::encryption::plaintext::Int64)]
298248
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TS, JsonSchema)]
299249
#[serde(deny_unknown_fields)]
300250
pub struct BigintEqQuery {
301-
#[cfg_attr(feature = "stack-encrypt", stash(default))]
251+
#[stash(default)]
302252
pub v: SchemaVersion,
303-
#[cfg_attr(feature = "stack-encrypt", stash(context_field))]
253+
#[stash(context_field)]
304254
pub i: Identifier,
305255
pub hm: Hmac256,
306256
}

‎packages/eql/crates/eql-bindings/src/v4/boolean.rs‎

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,18 @@ use ts_rs::TS;
1414
doc,
1515
doc = " See the [EQL boolean reference](https://cipherstash.com/docs/reference/eql/booleans) for SQL domain variants, operators, and query examples."
1616
)]
17-
#[cfg_attr(doc, doc = "")]
18-
#[cfg_attr(
19-
all(doc, feature = "stack-encrypt"),
20-
doc = " Plaintext input and decrypted output: [`Bool`](crate::encryption::plaintext::Bool). With the `stack-encrypt` feature, implements `EncryptFrom<Bool>` and `DecryptInto<Bool>`."
21-
)]
22-
#[cfg_attr(
23-
all(doc, not(feature = "stack-encrypt")),
24-
doc = " Plaintext input and decrypted output: `Bool`. With the `stack-encrypt` feature, implements `EncryptFrom<Bool>` and `DecryptInto<Bool>`."
25-
)]
26-
#[cfg_attr(
27-
all(doc, feature = "stack-encrypt"),
28-
doc = " Encryption context: `NonEmpty<Identifier>`, constructed with `Identifier::for_column(table, column)` and stored in `i`."
29-
)]
30-
#[cfg_attr(
31-
all(doc, feature = "stack-encrypt"),
32-
doc = " See the [complete encryption example](crate::encryption#example)."
33-
)]
34-
#[cfg_attr(feature = "stack-encrypt", derive(stack_encrypt::EncryptFrom))]
35-
#[cfg_attr(feature = "stack-encrypt", derive(stack_encrypt::DecryptInto))]
36-
#[cfg_attr(
37-
feature = "stack-encrypt",
38-
stash(plaintext = crate::encryption::plaintext::Bool)
39-
)]
17+
///
18+
/// Plaintext input and decrypted output: [`Bool`](crate::encryption::plaintext::Bool). Implements `EncryptFrom<Bool>` and `DecryptInto<Bool>`.
19+
/// Encryption context: `NonEmpty<Identifier>`, constructed with `Identifier::for_column(table, column)` and stored in `i`.
20+
/// See the [complete encryption example](crate::encryption#example).
21+
#[derive(stack_encrypt::EncryptFrom, stack_encrypt::DecryptInto)]
22+
#[stash(plaintext = crate::encryption::plaintext::Bool)]
4023
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, TS, JsonSchema)]
4124
#[serde(deny_unknown_fields)]
4225
pub struct Boolean {
43-
#[cfg_attr(feature = "stack-encrypt", stash(default))]
26+
#[stash(default)]
4427
pub v: SchemaVersion,
45-
#[cfg_attr(feature = "stack-encrypt", stash(context_field))]
28+
#[stash(context_field)]
4629
pub i: Identifier,
4730
pub c: Ciphertext,
4831
}

0 commit comments

Comments
 (0)