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
30 changes: 30 additions & 0 deletions docs/plans/2026-11-14-move-vitaminc-aead-into-the-stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,36 @@ Done (#1990):

A UUID then works in every SDK, which closes #1821.

Done (#1992):

- **TypeScript:** nothing removed on `next`. `is_uuid` and the
`recipher_js::uuid` code are only on the values and records branches
(#1775, #1776), and are removed there when they rebase. `OneValue` stays
on `next`: the addon's `keyset.encrypt` takes a string only, through the
engine's opaque scalar path, and that path needs a `Scalar`. An
`OwnedFrame` is not one, because it can hold an array.
- **Go:** the guest keeps its `Frame::parse`. It is not a second check:
the engine's readers take a `Frame`, and `Frame::parse` is the only way
to make one from the host's bytes. It also gives the Go SDK its "not a
frame" error before any key request. The two identical helpers are now
one, `parse_frame`, with a comment that says why.
- **EQL:** `Target::plaintext` is an `Option<ValueKind>`, and
`plaintext_kind` is gone. `eql-codegen`'s `plaintext_of` returns a
`ValueKind`, the generated table writes `ValueKind::Int32` and so on, and
the Go table writes `ValueKind::name`. The `Plaintext` trait already used
`ValueKind`. The wire format and the Go file did not change.
- **UUID:** Rust stores, queries by equality and reads a `uuid` field
(`dynamic::record`'s tests). The Go guest does too, through its record
and query exports (a new guest test). The Go SDK's `gensupport` takes a
UUID, but `stashgen` maps no Go type to the `uuid` kind, so generated
code cannot declare one yet. The TypeScript addon on `next` encrypts a
string only, so it cannot store a UUID. The values and records branches
still refuse a `VcUuid` with `recipher_js::uuid`, and test that refusal;
once they drop it, they need a test that stores, queries and reads one.
So #1821 stays open for `stashgen` and the addon.
- No stored bytes changed: the pinned fixtures and conformance cases pass
unchanged.

## Stage 3: move the Go packages

vitaminc has two Go packages that the Go module imports in about 60 places:
Expand Down
56 changes: 22 additions & 34 deletions languages/golang/encrypt/guest/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,11 @@ where
K: DataKeySource + IndexKeySource + Sync + 'static,
{
let plan = parse_plan(plan)?;
let tree =
dynamic::record::encrypt_with(cipher, checked_plaintext(source)?, &plan, &resolver())
.map_err(|e| fail_dynamic(&e))?
.audit(audit)
.await
.map_err(|e| fail_error(&e))?;
let tree = dynamic::record::encrypt_with(cipher, parse_frame(source)?, &plan, &resolver())
.map_err(|e| fail_dynamic(&e))?
.audit(audit)
.await
.map_err(|e| fail_error(&e))?;
encode_tree(tree)
}

Expand Down Expand Up @@ -293,7 +292,7 @@ where
&plan,
field,
operator,
checked_plaintext(input)?,
parse_frame(input)?,
&resolver(),
)
.map_err(|e| fail_dynamic(&e))?
Expand Down Expand Up @@ -363,14 +362,14 @@ pub fn verify(
let (plan, field, operator) = parse_query(plan, field, operator)?;
// Each value is a frame borrowed from the list's, walked in place: the
// bytes stay in the export's buffer, which wipes them when it drops.
let values = checked_plaintext(values)?
let values = parse_frame(values)?
.elements()
.ok_or_else(|| last_error::malformed("the values to verify are not a list"))?;
let verified = dynamic::verify(
&plan,
field,
operator,
checked_plaintext(input)?,
parse_frame(input)?,
values,
&resolver(),
)
Expand Down Expand Up @@ -573,8 +572,7 @@ pub mod validate {
/// against its field's outputs).
pub fn record(source: &Bytes, plan: &Bytes) -> Result<(), u32> {
let plan = parse_plan(plan)?;
dynamic::record::check_source(checked_plaintext(source)?, &plan)
.map_err(|e| fail_dynamic(&e))
dynamic::record::check_source(parse_frame(source)?, &plan).map_err(|e| fail_dynamic(&e))
}

/// A query's inputs, as [`query_term`](super::query_term) takes them:
Expand All @@ -589,14 +587,8 @@ pub mod validate {
operator: &[u8],
) -> Result<(), u32> {
let (plan, field, operator) = parse_query(plan, field, operator)?;
dynamic::check_query(
&plan,
field,
operator,
checked_plaintext(input)?,
&resolver(),
)
.map_err(|e| fail_dynamic(&e))
dynamic::check_query(&plan, field, operator, parse_frame(input)?, &resolver())
.map_err(|e| fail_dynamic(&e))
}

/// A read's inputs, as [`json_open`](super::json_open) takes them: the
Expand Down Expand Up @@ -630,16 +622,6 @@ pub mod validate {
// Codec glue
// =============================================================================

/// Plaintext from a frame: checked against the engine's value model and
/// walked in place from the buffer the export took it into, which wipes it
/// when it drops. The same frames are refused as control data's, so a
/// malformed input fails the same way on every path. Nothing is copied
/// here: the record split copies each field into its own wiped frame, and
/// a query's input is read straight into its term.
fn checked_plaintext(bytes: &Bytes) -> Result<Frame<'_>, u32> {
Frame::parse(lend(bytes).risky_ref()).map_err(|_| not_a_frame())
}

/// An opened value as the output buffer: its frame, copied into a buffer
/// whose capacity is exactly its length (see [`encode_tree`]); the frame
/// is wiped when it drops.
Expand All @@ -650,12 +632,18 @@ fn encode_frame(frame: OwnedFrame) -> Result<Vec<u8>, u32> {
Ok(out)
}

/// One frame, parsed and checked but not decoded: what a term's value is
/// walked from, in place.
/// One input as a frame, parsed and checked but not decoded: a value is
/// walked from it in place, from the buffer the export took it into, which
/// wipes it when it drops. Nothing is copied here.
///
/// This is the one place the guest reads an input's bytes itself:
/// vitaminc's frame parser takes a slice. Everywhere else an input is lent
/// to a reader ([`lend`]).
/// The parse is not a second check of what the engine checks. The engine's
/// value readers take a [`Frame`], and [`Frame::parse`] is the only way to
/// make one from bytes. It also refuses bytes that are not one well-formed
/// frame, before any key is requested and before that input's own grammar
/// is read, so the Go SDK reports "not a frame" for a malformed plan,
/// context or value alike. Query statistics, the options and the keyset
/// selector are not read through it: their own readers refuse malformed
/// bytes with errors of their own.
fn parse_frame(bytes: &Bytes) -> Result<Frame<'_>, u32> {
Frame::parse(bytes.risky_ref()).map_err(|_| not_a_frame())
}
Expand Down
57 changes: 57 additions & 0 deletions languages/golang/encrypt/guest/tests/native_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,63 @@ fn record_terms_equal_the_native_derivations_and_probe_them() {
assert!(matches!(value, Tree::UInt32(34)));
}

/// A `uuid` field is sealed with its equality term, opens to the UUID it
/// was given, and an `eq` query of the same UUID derives the stored term.
#[test]
fn a_uuid_field_round_trips_and_queries_by_equality() {
use stack_encrypt::dynamic::plaintext::Logical;
let uuid = |byte: u8| Tree::Typed(Logical::Uuid, Box::new(Tree::Bytes(vec![byte; 16])));
let cipher = cipher();
let plan = encode(obj(vec![(
"id",
obj(vec![
("context", label("id")),
("outputs", Tree::Array(vec![s("c"), s("eq")])),
("type", s("uuid")),
]),
)]));
let source = encode(obj(vec![("id", uuid(7))]));
ops::validate::record(&protect(&source), &protect(&plan)).expect("the source fits");
let record = block_on(ops::encrypt_record(
&cipher.default_keyset(),
&protect(&source),
&protect(&plan),
AuditMetadata::new(),
))
.expect("encrypt a uuid");

let opened = block_on(ops::decrypt_record(
&cipher,
&record,
&protect(&plan),
None,
AuditMetadata::new(),
))
.expect("decrypt a uuid");
assert_eq!(decode(&opened), obj(vec![("id", uuid(7))]));

let CipherText::Map(fields) = decode_tree(&record) else {
panic!("expected a field map");
};
let (_, CipherText::Map(outputs)) = &fields[0] else {
panic!("expected an output map");
};
let stored = term_bytes(&outputs[1].1);
let query = |value: Tree| {
let answer = block_on(ops::query_term(
&cipher.default_keyset(),
&protect(&encode(value)),
&protect(&plan),
b"id",
b"eq",
))
.expect("an eq query of a uuid");
bytes_of(entry(&query_term_entries(&answer), "term"))
};
assert_eq!(query(uuid(7)), stored, "the same UUID finds the row");
assert_ne!(query(uuid(8)), stored, "another UUID does not");
}

// =============================================================================
// Structured contexts
// =============================================================================
Expand Down
1 change: 1 addition & 0 deletions packages/eql/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/eql/crates/eql-bindings/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Earlier unreleased builds took and returned Stack Encrypt's
`dynamic::ValueFrame`, which is removed. The frame's bytes are the same,
so no stored value or query changes.
- **A target's plaintext kind is a `ValueKind`.** `Target::plaintext` is
`Option<ValueKind>` (`stack_encrypt::dynamic::ValueKind`), where it was
the kind's name as text, and `Target::plaintext_kind` is removed. The
generated table names each kind as `ValueKind::Int32` and so on, so a
name cannot drift from the engine's. The `se_targets` wire format still
writes the kind's name, so nothing a guest serializes changes.
- **A type that may hold a null reads any null as one.** A plaintext of a
type whose terms a null has reads a plain null, and a typed null of any
type, as absent, and seals it padded to its own type's length. A typed
Expand Down
2 changes: 1 addition & 1 deletion packages/eql/crates/eql-bindings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ that plan names its EQL type as a string (`"TextEq"`). The
`eql_bindings::encryption::targets` module is where the string meets the type.
`targets()` is the catalog-generated table of every EQL type a plan may name —
its name across languages, family and suffix, the plaintext kind it takes (a
vitaminc `ValueKind` name, the same names a plan field's `"type"` key uses), the
`ValueKind`, written by the name a plan field's `"type"` key uses), the
indexes it carries (`eq` / `match` / `ore` / `ope` / `json`), its query twin,
and whether the engine can produce it today, with the reason when not. A guest
serializes it for its `se_targets` export; the module docs are the wire format.
Expand Down
4 changes: 2 additions & 2 deletions packages/eql/crates/eql-bindings/src/encryption/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl From<&Target> for TargetDescriptor {
target.name,
target.family,
target.suffix,
target.plaintext_kind(),
target.plaintext,
target.sql_domain,
target.indexes.iter().map(|key| (*key).to_owned()).collect(),
target.query.map(str::to_owned),
Expand Down Expand Up @@ -233,7 +233,7 @@ mod tests {
#[test]
fn a_descriptor_has_its_rows_values() {
for (row, descriptor) in targets::targets().iter().zip(EqlTargets.targets()) {
assert_eq!(descriptor.plaintext, row.plaintext_kind(), "{}", row.name);
assert_eq!(descriptor.plaintext, row.plaintext, "{}", row.name);
assert_eq!(descriptor.producible, row.producible, "{}", row.name);
assert_eq!(
descriptor.match_options.is_some(),
Expand Down
34 changes: 14 additions & 20 deletions packages/eql/crates/eql-bindings/src/encryption/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
//! | `name` | The type's name, one across Rust, TypeScript and Go: the catalog struct identifier. The data plan's target form names this. (Go spells the `Json` family's types `JSON`; that rename is the Go generator's.) |
//! | `family` | The catalog family, lower case: `text`, `integer`, `json`, … |
//! | `suffix` | What a query can do, as the plan's table of suffixes spells it: `""` (stored and read only), `Eq`, `Ord`, `OrdOpe`, `OrdOre`, `Match`, `Search`, `SearchOre`; `""` too for a document family's stored type, whose queries are the JSON index's operators. |
//! | `plaintext` | The vitaminc [`ValueKind`] name the type is produced from — the same names a plan field's `"type"` key uses — or `null` while the family's plaintext encoding for the stack-encrypt producer profile is unspecified. |
//! | `plaintext` | The name of the [`ValueKind`] the type is produced from — the same names a plan field's `"type"` key uses — or `null` while the family's plaintext encoding for the stack-encrypt producer profile is unspecified. |
//! | `sql_domain` | The schema-qualified PostgreSQL domain the stored value inhabits. |
//! | `indexes` | The indexes the type carries, by the engine's `IndexSpec::key()` names: `eq`, `match`, `ore`, `ope`, and `json` for a document family's stored type. A query may ask a field typed with this target for exactly these. |
//! | `query` | The query twin's type name (`TextEqQuery`, `JsonSearchQuery`), or `null` for a storage-only type, which answers no query. |
Expand Down Expand Up @@ -126,10 +126,10 @@ pub struct Target {
pub family: &'static str,
/// The query-capability suffix: `Eq`; empty for a storage-only type.
pub suffix: &'static str,
/// The [`ValueKind`] name of the plaintext this type is produced from,
/// or `None` while the family's encoding is unspecified. See
/// [`plaintext_kind`](Self::plaintext_kind) for the parsed kind.
pub plaintext: Option<&'static str>,
/// The kind of plaintext this type is produced from, or `None` while the
/// family's encoding is unspecified. On the wire it is the kind's name.
#[serde(serialize_with = "kind_name")]
pub plaintext: Option<ValueKind>,
/// The stored value's PostgreSQL domain: `public.eql_v4_text_eq`.
pub sql_domain: &'static str,
/// The indexes the type carries, by `IndexSpec::key()` name.
Expand All @@ -144,15 +144,16 @@ pub struct Target {
pub reason: Option<&'static str>,
}

impl Target {
/// The plaintext kind, parsed. `None` when the table records none; the
/// table is generated from names vitaminc freezes, so a recorded name
/// always parses, and a `None` here means the same as a `None` in
/// [`plaintext`](Self::plaintext).
pub fn plaintext_kind(&self) -> Option<ValueKind> {
self.plaintext.and_then(|name| name.parse().ok())
}
/// Writes a plaintext kind as its name, the name a plan field's `"type"`
/// key spells, or `null` when there is none.
fn kind_name<S: serde::Serializer>(
kind: &Option<ValueKind>,
serializer: S,
) -> Result<S::Ok, S::Error> {
kind.map(ValueKind::name).serialize(serializer)
}

impl Target {
/// The PostgreSQL domain of the type's ordering operand at a path, for
/// a type that stores a JSON document (`JsonSearch`:
/// `eql_v4.query_json_leaf`); `None` for every other type. Stack
Expand Down Expand Up @@ -1043,12 +1044,6 @@ mod tests {
"{}: a reason exactly when not producible",
t.name
);
assert_eq!(
t.plaintext_kind().is_some(),
t.plaintext.is_some(),
"{}: a recorded plaintext name is a vitaminc kind",
t.name
);
}
}

Expand Down Expand Up @@ -1098,7 +1093,6 @@ mod tests {
"reason": "its encoding is not decided"
})
);
assert_eq!(WAITING.plaintext_kind(), None);
}

#[test]
Expand Down
Loading
Loading