Skip to content

Commit 40c39a2

Browse files
committed
refactor(eql-bindings): take the Rust primitives as the v4 number and boolean plaintexts
Integer, Bigint, Boolean, Real and Double, and their equality types, now take i32, i64, bool, f32 and f64, as the text types take String. The encryption::plaintext newtypes are gone: the derive and the by-name dispatch need nothing a primitive lacks, and the dispatch still accepts only the matching runtime kind. A typed decrypt now reads a leaf as vitaminc reads it into the primitive: an integer of another width that fits opens unchanged, and an f64 opens an f32. A value that does not fit, or of another kind, is still refused. The newtypes refused every other width, but every writer seals at the type's width, so that refused only payloads none of them writes. eql-bindings no longer depends on vitaminc-aead directly.
1 parent 7c8e018 commit 40c39a2

17 files changed

Lines changed: 182 additions & 408 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, 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.
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 Rust primitives `i32`, `i64`, `bool`, `f32` and `f64`; 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/encrypt/guest/Cargo.lock‎

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/eql/Cargo.lock‎

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
that feature alone, and its producible types derive `EncryptFrom` and
1515
`DecryptInto` with no attribute of their own gated on it.
1616
- **`IntegerEq`, `BigintEq`, `RealEq` and `DoubleEq` are producible**
17-
(`stack-encrypt` feature), from the `Int32`, `Int64`, `Float32` and
18-
`Float64` plaintexts. Their equality term follows ADR-0002's semantic
17+
(`stack-encrypt` feature), from `i32`, `i64`, `f32` and `f64`. Their equality term follows ADR-0002's semantic
1918
baseline, so `=` compares as PostgreSQL's own integer and `float8 =` do:
2019
one term per integer value whatever its width, `-0.0 = 0.0` and
2120
`NaN = NaN`. The ciphertext keeps the exact value.

‎packages/eql/crates/eql-bindings/Cargo.toml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ schemars = "1"
4747
# target takes and the kind names a plan's `"type"` key spells
4848
# (`encryption::targets`).
4949
stack-encrypt = { path = "../../../stack-encrypt", version = "0.3.0", optional = true, default-features = false, features = ["dynamic"] }
50-
# `Physical`, `Int`, `Float` and `FromScalar`: the scalar plaintexts in
51-
# `encryption::plaintext` describe themselves through vitaminc's `Encrypt`
52-
# and read back only their own width through `FromScalar`.
53-
vitaminc-aead = { version = "0.6.0", optional = true }
5450
# The plaintext a target reads out of its `Protected` runtime value is held
5551
# in `Zeroizing` until it is sealed, so the copy is wiped like the original.
5652
zeroize = { version = "1", optional = true }
@@ -62,7 +58,6 @@ hex = { version = "0.4", optional = true }
6258
default = []
6359
stack-encrypt = [
6460
"dep:stack-encrypt",
65-
"dep:vitaminc-aead",
6661
"dep:zeroize",
6762
"dep:thiserror",
6863
"dep:base64",

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,17 @@ The optional `stack-encrypt` feature enables `EncryptFrom<String>` for
106106
`v4::text::TextEq`. Stack Encrypt writes EQL v4 only, so no `v3` type
107107
implements these traits. The derives are emitted by `eql-codegen`.
108108

109-
The other v4 types Stack Encrypt produces take a plaintext from
110-
`eql_bindings::encryption::plaintext`, which seal as the primitive they wrap
111-
and read back only a value of their own width:
109+
The other v4 types Stack Encrypt produces take a Rust primitive as their
110+
plaintext:
112111

113112
| v4 type | Plaintext |
114113
| --- | --- |
115114
| `Text`, `TextMatch` | `String` |
116-
| `Integer`, `IntegerEq` | `Int32` |
117-
| `Bigint`, `BigintEq` | `Int64` |
118-
| `Boolean` | `Bool` |
119-
| `Real`, `RealEq` | `Float32` |
120-
| `Double`, `DoubleEq` | `Float64` |
115+
| `Integer`, `IntegerEq` | `i32` |
116+
| `Bigint`, `BigintEq` | `i64` |
117+
| `Boolean` | `bool` |
118+
| `Real`, `RealEq` | `f32` |
119+
| `Double`, `DoubleEq` | `f64` |
121120

122121
Each seals the leaf the value enum (`FfiValue`) seals for the same value, so
123122
values written here and by the Go SDK open each other. On the equality

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
//! require::<TextEq>();
8181
//! ```
8282
83-
pub mod plaintext;
8483
pub mod targets;
8584

8685
use base64::{engine::general_purpose::STANDARD, Engine as _};

‎packages/eql/crates/eql-bindings/src/encryption/plaintext.rs‎

Lines changed: 0 additions & 213 deletions
This file was deleted.

‎packages/eql/crates/eql-bindings/src/encryption/targets.rs‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ use stack_encrypt::{
9191
DecryptInto, EncryptFrom, Error, KeysetCipher, Label, NonEmpty, Pending, StackCipher,
9292
};
9393

94-
use super::plaintext;
9594
use crate::v4::targets::{decrypt_named, encrypt_named, query_named, TARGETS};
9695
use crate::Identifier;
9796

@@ -402,15 +401,13 @@ pub(crate) fn refuse(name: &str) -> TargetError {
402401
}
403402

404403
mod sealed {
405-
use super::plaintext::{Bool, Float32, Float64, Int32, Int64};
406-
407404
pub trait Sealed {}
408405
impl Sealed for String {}
409-
impl Sealed for Int32 {}
410-
impl Sealed for Int64 {}
411-
impl Sealed for Bool {}
412-
impl Sealed for Float32 {}
413-
impl Sealed for Float64 {}
406+
impl Sealed for i32 {}
407+
impl Sealed for i64 {}
408+
impl Sealed for bool {}
409+
impl Sealed for f32 {}
410+
impl Sealed for f64 {}
414411
}
415412

416413
/// A Rust plaintext an EQL type is produced from, read out of and written
@@ -460,12 +457,12 @@ impl Plaintext for String {
460457
/// the declared kind's.
461458
macro_rules! scalar_plaintext {
462459
($($ty:ident => $variant:ident),+ $(,)?) => {$(
463-
impl Plaintext for plaintext::$ty {
460+
impl Plaintext for $ty {
464461
const KIND: ValueKind = ValueKind::$variant;
465462

466463
fn from_value(target: &'static str, value: FfiValue) -> Result<Self, TargetError> {
467464
match value {
468-
FfiValue::$variant(v) => Ok(plaintext::$ty(v)),
465+
FfiValue::$variant(v) => Ok(v),
469466
other => Err(TargetError::Plaintext {
470467
target,
471468
expected: Self::KIND,
@@ -475,17 +472,17 @@ macro_rules! scalar_plaintext {
475472
}
476473

477474
fn into_value(self) -> FfiValue {
478-
FfiValue::$variant(self.0)
475+
FfiValue::$variant(self)
479476
}
480477
}
481478
)+};
482479
}
483480
scalar_plaintext!(
484-
Int32 => Int32,
485-
Int64 => Int64,
486-
Bool => Bool,
487-
Float32 => Float32,
488-
Float64 => Float64,
481+
i32 => Int32,
482+
i64 => Int64,
483+
bool => Bool,
484+
f32 => Float32,
485+
f64 => Float64,
489486
);
490487

491488
/// Run a target's own plan over one runtime value and resolve to the EQL

0 commit comments

Comments
 (0)