Skip to content

Commit 5b9f4bd

Browse files
committed
fix(encrypt)!: address review of the owned scalar API
- Rename the structural entry points encrypt_node / decrypt_node to encrypt_tree / decrypt_tree. - Rename the sealed Scalar trait to OpaqueEncode / OpaqueDecode, the names the API plan accepted. Both stay sealed. - Rename Ciphertext::tag to key_tag, so it cannot be read as the AEAD tag. - Give Ciphertext Serde: padded Base64 in human-readable formats, raw bytes in binary ones. - Report a non-single tree as Error::OpenedType, not Error::Aead (ADR-0010). - Restore NonEmpty on the shared encrypt/open core. The scalar path reaches the core through its own entry that allows empty context, and ADR-0003 records the exception. - Open bytes written by the pre-scalar build through Ciphertext. - Kill the three mutants CI missed. The NoCallerContext conversion is equivalent and is excluded. - Add the CHANGELOG Breaking entries and drop roadmap prose from rustdoc.
1 parent 6d2fc0e commit 5b9f4bd

26 files changed

Lines changed: 399 additions & 123 deletions

‎.cargo/mutants.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ exclude_re = [
8181
'stack-encrypt/src/sem/mod\.rs:\d+:\d+: replace <impl MatchConfig for DefaultMatch>::options -> MatchOptions with Default::default\(\)$',
8282
# Both unit-context conversions explicitly return Self::default().
8383
'stack-encrypt/src/target/context\.rs:\d+:\d+: replace <impl From<\(\)> for (DeclaredContext|ExpectedContext<T>)>::from -> Self with Default::default\(\)$',
84+
# A caller-free declaration adds nothing to the declared context: the
85+
# conversion returns Self::default().
86+
'stack-encrypt/src/target/input\.rs:\d+:\d+: replace <impl From<NoCallerContext> for super::DeclaredContext>::from -> Self with Default::default\(\)$',
8487
# The resolver of a build without EQL types holds none: its `targets` IS
8588
# the empty list (`dynamic::target::NoTargets`), which a test asserts on
8689
# and `resolve` turns into `TargetError::NoTargets`; `vec![]` is the body.

‎.changeset/stack-encrypt-owned-scalars.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ Stack Encrypt's Rust scalar API now consumes plaintext and returns an opaque
66
`EncryptInto` / `DecryptFrom` conversions use explicit context capabilities.
77
The stored sealed-leaf format is unchanged.
88

9+
Low-level structural encryption and decryption use `encrypt_tree` and
10+
`decrypt_tree`, returning and opening a tree of individually sealed leaves.
11+
912
This is a Rust-only release, versioned by release-plz from the conventional
1013
commit. No npm package needs a version bump; EQL changes only adapt tests.

‎Cargo.lock‎

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

‎packages/eql/tests/encryption/tests/text_eq.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async fn text_round_trips_through_json_and_both_canonical_directions() {
5252
let opened: String = cipher.decrypt_as(stored, Default::default()).await.unwrap();
5353
assert_eq!(opened, value);
5454

55-
let native = keyset.encrypt_node(value.clone(), column()).await.unwrap();
55+
let native = keyset.encrypt_tree(value.clone(), column()).await.unwrap();
5656
let stored = TextEq {
5757
v: SchemaVersion::CURRENT,
5858
i: column().into_inner(),

‎packages/eql/tests/encryption/tests/v4_types.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async fn sealed_from_frame(
8484
keyset: &stack_encrypt::KeysetCipher<'_, common::Observed>,
8585
value: ValueFrame,
8686
) -> Ciphertext {
87-
match keyset.encrypt_node(value, column()).await.unwrap() {
87+
match keyset.encrypt_tree(value, column()).await.unwrap() {
8888
CipherText::Single(leaf) => CiphertextVisitor.sealed(leaf).unwrap(),
8989
_ => panic!("a scalar seals as one leaf"),
9090
}

‎packages/stack-encrypt/CHANGELOG.md‎

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

1010
### Breaking
1111

12+
- **`KeysetCipher::encrypt` and `decrypt` are the owned scalar API.**
13+
`keyset.encrypt(value)` consumes an `OpaqueEncode` value (`bool`, the fixed-width
14+
integers except `u8`, `f32`, `f64`, `String`), wipes it, and returns one
15+
opaque `Ciphertext`; `keyset.decrypt::<T>(ciphertext)` opens it to an `OpaqueDecode` type.
16+
`encrypt_with_context` and `decrypt_with_context` bind a context. The
17+
previous structural forms, which take any `Encrypt` value and a context and
18+
return a `StackCipherText`, are renamed `encrypt_tree` and `decrypt_tree`.
19+
`Ciphertext`'s bytes are the unchanged `SealedValue` v1 envelope, so
20+
stored values open through either API.
21+
- **The root `EncryptInto` and `DecryptFrom` are new owned conversion
22+
traits** over `EncryptTarget` / `DecryptSource`. The borrowed traits they
23+
replace, and that `#[derive(EncryptFrom, DecryptInto)]` types use, are
24+
`stack_encrypt::target::legacy::{EncryptInto, DecryptFrom}`; import one
25+
pair or the other, not both.
1226
- **`OpSpec`, `Operand` and the query term's wire form grow for documents**
1327
(#1350). `OpSpec` gains twelve operators and `Operand` gains `Text` and
1428
`TextList`; a binding that matches on either adds the arms. The query

‎packages/stack-encrypt/Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ trybuild = "1"
143143
# stack-guest-abi takes it: `std` carries the failure persistence and the
144144
# ChaCha RNG the runs are seeded with, and nothing else is needed.
145145
proptest = { version = "1.12", default-features = false, features = ["std"] }
146+
# A binary Serde format for `Ciphertext`'s bytes form (tests/scalar.rs).
147+
# Already in the graph through vitaminc-traits.
148+
rmp-serde = "1.3"
146149

147150
# The derive diagnostics are recorded with every feature on, as `test:unit`
148151
# and CI run them. They cannot be relied on to hold under both feature sets

‎packages/stack-encrypt/docs/adr/0003-declarative-targets-and-ciphertext-transcoding.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ not close it. A concrete associated context type does not implicitly accept
6161
arbitrary context extensions; any extension facility must preserve the declared
6262
base context and be specified explicitly.
6363

64+
Amended 2026-10-31: the opaque scalar `Ciphertext` is the one target-directed
65+
output that accepts empty context, because it is the cipher-directed
66+
contract in owned form: `keyset.encrypt(value)` seals what
67+
`keyset.encrypt_tree(value, ())` seals. It reaches the shared core through a
68+
separate entry. Every other target goes through the entry that takes a
69+
`NonEmpty`, so the nonempty requirement stays in the type.
70+
6471
Transcoding consumes native encryption output through a custom encrypted-data
6572
protocol. It distinguishes sealed leaves, sequences, maps, authenticated absence
6673
and empty-container markers, passthrough metadata, and typed terms. Readers expose

‎packages/stack-encrypt/examples/mixed_user.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
126126
// in the whole Vec (here: 3 rows x 2 encrypted fields = 6 data keys).
127127
let ciphertext = cipher
128128
.default_keyset()
129-
.encrypt_node(users, record.clone())
129+
.encrypt_tree(users, record.clone())
130130
.await?;
131131

132132
println!("what the stored ciphertext reveals:");

‎packages/stack-encrypt/examples/zerokms_auth.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
5656
let keyset = cipher.default_keyset();
5757
println!("connected; keyset {}", keyset.keyset_id());
5858

59-
let ciphertext = keyset.encrypt_node("hello", "demo/greeting").await?;
59+
let ciphertext = keyset.encrypt_tree("hello", "demo/greeting").await?;
6060
let plaintext: String = cipher.decrypt(ciphertext, "demo/greeting").await?;
6161
assert_eq!(plaintext, "hello");
6262
println!("round-tripped a value under the default keyset");
@@ -72,7 +72,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
7272
// let customers = cipher
7373
// .keyset(IdentifiedBy::Name("customers".to_string().into()))
7474
// .await?;
75-
// let ciphertext = customers.encrypt_node("hello", "demo/greeting").await?;
75+
// let ciphertext = customers.encrypt_tree("hello", "demo/greeting").await?;
7676
//
7777
// `default_keyset()` above is not one of these: it is the client's own
7878
// default, the keyset a ZeroKMS administrator set for this client, and

0 commit comments

Comments
 (0)