Skip to content

Go SDK: a value cannot be encrypted without a context, or without a struct — add plain Encrypt and Decrypt on Cipher #1771

Open

Description

@coderdan

Background

Stack Encrypt (packages/stack-encrypt) is the Rust engine that every CipherStash language SDK runs on. The Go SDK (languages/golang/encrypt) runs the engine inside a WebAssembly module.

Every value is encrypted under its own data key from ZeroKMS, CipherStash's key service. A value can also be encrypted under a context: a name, such as a table or a tenant, that the ciphertext is tied to. The ciphertext then decrypts only under the same context.

In Rust, a context is optional. The simplest call takes a value and nothing else:

let ciphertext = keyset.encrypt("secret message".to_owned()).await?;
let plaintext: String = keyset.decrypt(ciphertext).await?;

encrypt_with_context is the form that takes a context (packages/stack-encrypt/src/lib.rs, "Quick start").

Problem

The Go SDK cannot encrypt a value with no context. It has two gaps:

  1. There is no call that encrypts one value. The only way to encrypt is through a struct with stash tags and the code that stashgen, the SDK's generator, writes for it. Cipher has Seal and Open for records and no method for a single value (languages/golang/encrypt/records.go:46 and :114).
  2. Every struct must declare a context. stashgen refuses a struct that has neither a context= tag nor a context_field, with "no _ struct{} field with stash:"context=..." declares the context, and no field is tagged context_field" (languages/golang/stashgen/read.go:255). The generator's README lists this as a refused declaration (languages/golang/cmd/stashgen/README.md:456).

So a Go program that wants to encrypt one string, a token or a file must define a struct, invent a context name, run the generator and commit the generated file. A Rust program does the same in one line.

It also means Go cannot open a value that Rust encrypted with keyset.encrypt(value), and Rust code that expects a value with no context cannot open what Go wrote.

Nothing catches this, because it is a missing feature and not a failing test. The cross-language conformance suite (conformance/stack-encrypt) has no case for a value encrypted with no context.

Proposal

  1. Add a call on Cipher that encrypts a batch of values with no context and returns one Ciphertext for each. Add the matching call that decrypts them. They need no struct, no tag and no generated code.
  2. Run them through the engine's own no-context path, so the bytes are the ones Rust's keyset.encrypt(value) writes.
  3. Keep the rule that a struct with stash tags declares a context. This issue adds plain encryption of a value. It does not change records.
  4. Add a conformance case: Rust encrypts a value with no context and Go opens it, and Go encrypts one and Rust opens it.
  5. Document the call in languages/golang/encrypt/README.md as the first example, before the struct tags.

Decide in the pull request whether the call also takes a form with a context, as Rust's encrypt_with_context does.

Evidence

Read on next at e62420d8e:

  • git grep "^func (.*\*Cipher)" -- languages/golang/encrypt/*.go lists no method that takes a single value. The methods that encrypt are Seal, QueryTerm and the unexported derive, and each takes a *record.Plan.
  • languages/golang/stashgen/read.go:255 is the refusal of a struct with no context.

Not checked: whether the engine's WebAssembly guest already exports the no-context path, or needs a new export.

Relationship to other work

Activity

  1. added
    bug
    on Nov 23, 2026
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

    SDKbug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions