Skip to content

stack-encrypt: the encrypted tree of a record has no serde, so each binding writes its own conversion #2029

Backlog

Description

@coderdan

Background

Stack Encrypt (packages/stack-encrypt) is the Rust library that does the encryption for every CipherStash language SDK. A language SDK reaches it through a language binding: a thin layer of Rust between the language and Stack Encrypt.

When Stack Encrypt encrypts a record, the result is a tree, StackCipherText. The tree has one entry for each field. A field's entry has one node for each output. c is the ciphertext. eq, match, ore, and ope are the index terms.

A decrypt call takes the same tree back.

The rule for bindings is that the code exists once, in Stack Encrypt. A binding does not repeat that code. A binding does not work around something that Stack Encrypt lacks.

Problem

A binding has to move that tree to its language and back. Stack Encrypt gives it no way to do that.

  • The tree's type is CipherText<Leaf, P> (packages/vitaminc-aead/src/container.rs). It has no Serialize or Deserialize. Its doc says that each host converts it to its own structures.
  • The leaf, SealedValue, does have serde and a byte form (packages/stack-encrypt/src/cipher.rs).

So each binding writes the conversion itself:

  • Go. The guest has encode_tree, decode_tree, map_leaves, and tree_encoded_len (languages/golang/encrypt/guest/src/ops.rs). They walk the tree, convert each leaf to bytes, and write the transport encoding. The Go module then decodes that encoding in Go.
  • TypeScript. The binding in feat(recipher-js): records through the engine's Planned #1776 has stored_row and stored_tree, about 170 lines. They walk the tree in both directions. They also rename Stack Encrypt's output names, and check the tree's shape a second time.

Each copy is code that can go wrong at a security boundary. A tree that a binding reads comes from storage, so an attacker can write it. Stack Encrypt already checks a tree's shape when it decrypts. A second check in each binding can disagree with it.

Proposal

  1. Give the encrypted tree one conversion that every binding uses. The simplest form is serde on the tree, with each leaf written as its bytes (SealedValue::to_bytes). A binding then writes the tree to a frame with the frame's serde (recipher-frame), and reads it back the same way.
  2. Decide where that lives: on CipherText in vitaminc-aead, or as a function in stack_encrypt::dynamic over StackCipherText.
  3. Keep Stack Encrypt's output names as they are: c, eq, match, ore, ope, and passthrough. No binding renames them.
  4. State that this is a transport form and not a storage format, as the leaf's serde already says.

Relationship to other work

Activity

  1. added
    enhancement
    Rust
    on Nov 29, 2026
  2. coderdan commented on Nov 30, 2026

    @coderdan
    ContributorAuthor

    The typed record that this issue asks for is being built in #2031. Its target output is named target, not eql. #2033 covers the same rename for the tree form and the rest of Stack Encrypt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    RustSDKenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions