Repository navigation
feat(stack-encrypt): typed encrypted records that cross to a language binding through serde #2031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
coderdan
wants to merge
11
commits into
next
Choose a base branch
from
feat/stack-encrypt-tree-frame
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+6,780
−170
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
de9d08c
feat(stack-encrypt): convert a stored record to a frame and back
coderdan 1c47a54
docs(stack-encrypt): list the stored-record frame functions in the dy…
coderdan 8eb4d74
fix(stack-encrypt): name the row and output of a stored-frame refusal
coderdan a2fd232
test(conformance): add the stored-frame profile, with the Go runner p…
coderdan 95b5604
test(stack-encrypt): keep generated dates and timestamps in the engin…
coderdan 0302e15
test(stack-encrypt): move the stored-frame unit tests into a tests di…
coderdan a9f0c1c
Merge remote-tracking branch 'origin/next' into feat/stack-encrypt-tr…
coderdan 113e136
feat(recipher-frame): write and read a raw frame node through serde
coderdan cb63d84
feat(stack-encrypt): an encrypted record as typed values, through serde
coderdan a069729
test(conformance): replace the stored-frame profile with record-encry…
coderdan 495b6d1
test: catch the mutants that survived in the typed record and raw node
coderdan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
conformance/stack-encrypt/encrypted-records-contract.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| # Encrypted-record profile | ||
|
|
||
| `record-encrypted-v1` is the conformance profile for an encrypted record as | ||
| typed values, and for the frame that a language binding moves it in. The | ||
| cases are in `v1/record-encrypted-v1.cases.json`. The profile is an | ||
| experimental test contract. | ||
|
|
||
| A binding asks `record::encrypt` for an `EncryptedRecord`, or a batch of | ||
| them, and gives one back to `record::decrypt`. It moves the record to its | ||
| language and back as a frame, with `EncryptedRecord::to_frame` and | ||
| `EncryptedRecord::from_frame`. The cases fix the form of that frame, so | ||
| every binding builds and reads the same values. | ||
|
|
||
| ## Terms | ||
|
|
||
| - A frame is one value written as bytes, in the format that Stack Encrypt | ||
| reads. | ||
| - An encrypted record has one entry for each field. Each field has one | ||
| entry for each output. | ||
| - An output is one of these: | ||
| - `c`, the sealed value | ||
| - an index term: `eq`, `match`, `ore`, `ope`, or `ore_block` | ||
| - `passthrough`, a field's value stored without encryption | ||
| - `target`, the value of a field that names a target type | ||
| - A sealed value is the encrypted form of one scalar. Its bytes are stable. | ||
| - A refusal is an error that Stack Encrypt returns for a value or a frame | ||
| it does not accept. | ||
|
|
||
| ## Runners | ||
|
|
||
| The Rust runner is | ||
| `packages/stack-encrypt/tests/encrypted_record_conformance.rs`. The Go | ||
| runner is pending: the Go guest does not use typed records yet. The Python | ||
| and TypeScript runners are pending too. A missing runner is not a passing | ||
| result. | ||
|
|
||
| ## Cases | ||
|
|
||
| Each case has these keys: | ||
|
|
||
| | Key | Meaning | | ||
| |---|---| | ||
| | `id` | The name of the case | | ||
| | `plan` | The plan, in the [declaration grammar](declaration-grammar.md) | | ||
| | `batch` | Whether the rows are a batch. Without a batch, `rows` has one row. | | ||
| | `rows` | The rows to encrypt, as values | | ||
| | `frame` | The frame form that the encrypted record must have | | ||
| | `mutation` | A change to the frame before it is read back | | ||
| | `opened` | The rows that the frame, read back, decrypts to | | ||
| | `expected_error` | The `stage` of the refusal, and its `code` and payload `fields` | | ||
|
|
||
| A case has `opened` or `expected_error`, never both. | ||
|
|
||
| ### Values | ||
|
|
||
| `rows` and `opened` write a value in one of these ways: | ||
|
|
||
| | Form | The value | | ||
| |---|---| | ||
| | `{"type": ..., "text": ...}` | A scalar, as the [value profile](values-contract.md#cases) defines it | | ||
| | an array of values | A list | | ||
| | `{"$object": {...}}` | A map of values | | ||
| | `null` | A null | | ||
|
|
||
| A row leaves out a field that it does not have. | ||
|
|
||
| ### Frame nodes | ||
|
|
||
| `frame` and the `value` of a mutation write a node of the frame in one of | ||
| these ways: | ||
|
|
||
| | Form | The node | | ||
| |---|---| | ||
| | `"$sealed"` | The bytes of a sealed value | | ||
| | `"$bytes"` | Any bytes, such as a term. `frame` only. | | ||
| | `{"$value": <value>}` | The frame of a value, such as a passthrough field's value | | ||
| | `{"$hex": "..."}` | These bytes | | ||
| | `{"$passthrough": <node>}` | A passthrough node of the frame, around another node. Mutations only. | | ||
| | other text | That text | | ||
| | `null` | A null | | ||
| | an array | An array of nodes | | ||
| | another object | An object of nodes | | ||
|
|
||
| In a mutation, `"$sealed"` is the bytes of the first sealed value in the | ||
| frame that the runner wrote. | ||
|
|
||
| Objects compare by key. The order of the keys in the corpus file is not | ||
| significant. The order of a frame's keys is Stack Encrypt's. The runner | ||
| does not check it. | ||
|
|
||
| ### Mutations | ||
|
|
||
| A mutation has a `path`, an `op`, and, for `set`, a `value`. Each step of | ||
| the path is a key of an object, or a position in an array, counted from 0. | ||
|
|
||
| - `set` puts `value` at the path. It adds the key when the object has none. | ||
| - `remove` takes the key at the path out of its object. | ||
| - `duplicate` writes the entry at the path a second time. | ||
| - An empty path sets the whole frame. | ||
|
|
||
| ## Required behavior | ||
|
|
||
| For each case, the runner does this: | ||
|
|
||
| 1. It reads the plan, and encrypts the rows as one `EncryptedRecord`, or as | ||
| a batch of them. | ||
| 2. It writes the record as a frame. Where the case has `frame`, the frame | ||
| has that form. | ||
| 3. It applies the mutation, where the case has one. | ||
| 4. It parses the frame, reads it back as a record, and decrypts the record. | ||
| 5. For a case with `opened`, every step succeeds. With no mutation, the | ||
| record read back writes the same frame again. The record decrypts to | ||
| the `opened` rows. | ||
| 6. For a case with `expected_error`, the step that its `stage` names is | ||
| refused, with the `code`, and with a payload equal to `fields`. Every | ||
| step before it succeeds. | ||
|
|
||
| | Stage | The step that is refused | | ||
| |---|---| | ||
| | `encrypt` | `record::encrypt`, before any key is requested | | ||
| | `frame` | Parsing the frame. The case has no `code` or `fields`. | | ||
| | `read` | Reading the frame as a record | | ||
| | `decrypt` | `record::decrypt`, before any key is retrieved | | ||
|
|
||
| The cases cover these things: | ||
|
|
||
| - Every output kind: a sealed value, each index term, an index term alone, | ||
| and a passthrough field. | ||
| - A passthrough field of each value kind, and a passthrough that is a list | ||
| or a map. | ||
| - A batch, and an empty batch. | ||
| - A field with `"null": "sql"` and no value. It has no entry, and decrypts | ||
| as a null. | ||
| - A field with `"null": "sealed"` and no value. It is sealed. | ||
| - A `"null": "sql"` field that the frame leaves out. It decrypts as a null. | ||
| - Index terms left out of the frame. `decrypt` does not read them. | ||
| - The refusals, listed in the next table. | ||
|
|
||
| | Refusal | Stage | Reason | | ||
| |---|---|---| | ||
| | A sealed field whose value is a list, a map, or an empty one | `encrypt` | `not_one_value` | | ||
| | A frame that is not an object, or not an array of objects | `read` | `not_an_object` | | ||
| | A field that is not an object of outputs, a null included | `read` | `outputs_not_map` | | ||
| | A key that is not an output, such as `eql` | `read` | `not_an_output` | | ||
| | Anything under `c` but one sealed value's bytes | `read` | `not_sealed` | | ||
| | A term that is not bytes | `read` | `not_passthrough` | | ||
| | A field name given twice | `frame` | none | | ||
| | A sealed field with no `c` | `decrypt` | `no_ciphertext_node` | | ||
| | A passthrough of another type than its field declares | `decrypt` | `field_type` | | ||
| | A refusal of a row of a batch | any | the refusal's reason, with the row | | ||
|
|
||
| ## Refusals | ||
|
|
||
| The code of an `encrypt` refusal is `stack_encrypt::dynamic_source`. The | ||
| code of a `read` or `decrypt` refusal is `stack_encrypt::dynamic_record`. | ||
| The payload has these fields, where they apply: | ||
|
|
||
| | Field | Meaning | | ||
| |---|---| | ||
| | `reason` | What was wrong, such as `not_an_output` or `not_sealed` | | ||
| | `field` | The field at fault | | ||
| | `output` | The output at fault, such as `c` or `eq` | | ||
| | `row` | The row of a batch, counted from 0 | | ||
| | `found` | The kind of a frame, or a row, that is not an object | | ||
|
|
||
| No refusal contains a value, or a key that is not an output. | ||
|
|
||
| ## Scope and remaining work | ||
|
|
||
| The profile does not cover these: | ||
|
|
||
| - A field that names a target type. The EQL profile covers target values, | ||
| and the native tests cover their `target` output. | ||
| - One field's frame alone (`EncryptedField::to_frame` and `from_frame`). | ||
| The native tests cover it. | ||
| - The stored tree, `StackCipherText`. Other profiles cover it. | ||
| - Frames exchanged between languages. That needs a second runner. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit (optional): the table says
frameand a mutationvalueboth take{"$hex": "..."}. The Rust runner reads$hexonly in a mutation (shaped). Incheck, an object with$hexis compared as an object with the key$hex, so a case that uses it inframefails with "is not an object". Fix: mark$hexas "Mutations only", as$passthroughis, or handle it incheck.