Skip to content

Commit 05d19b3

Browse files
committed
docs(stack-encrypt): say why a document is parsed twice and how target options are refused
check_field parses a json field's document and drops it, and the resolver parses it again when it seals: the check runs before any key and needs no resolver, and a resolver takes the field's value as a frame. Options are read in the JSON index's grammar whatever the target, so options outside it are an invalid target while well-formed options on a target that takes none are target_options; the rustdoc on TargetWire now says both. Claude-Session: https://claude.ai/code/session_01N7bCqa3ZVJMcEE99RzVqEu
1 parent f2573fe commit 05d19b3

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎packages/stack-encrypt/src/dynamic/record.rs‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,14 @@ impl TryFrom<FieldSpecWire> for FieldSpec {
14101410
/// defaults, or an object of its name and its options, which are the
14111411
/// options of the index the target carries (the JSON index's options
14121412
/// object, as an output spells it).
1413+
///
1414+
/// The options are read in the JSON index's grammar whatever the target,
1415+
/// since that is the only grammar any target takes, and the target is
1416+
/// resolved after: options that are not that grammar (`{"x": 1}`) make
1417+
/// the target unreadable ([`Reason::InvalidTarget`]), and well-formed
1418+
/// options on a target that takes none (`{}` on `TextEq`) are
1419+
/// [`Reason::TargetOptions`]. Both refuse the plan before anything is
1420+
/// sealed.
14131421
#[derive(Deserialize)]
14141422
#[serde(untagged)]
14151423
enum TargetWire {
@@ -2393,7 +2401,13 @@ fn check_field(value: &ValueFrame, field: &FieldPlan) -> Result<(), Error> {
23932401
}
23942402
}
23952403
// A document is read by the engine's rules here, before any key, so a
2396-
// check refuses what encrypt refuses, and no resolver has to.
2404+
// check refuses what encrypt refuses, and no resolver has to. The
2405+
// parse is kept to a check and the document dropped (wiped, as every
2406+
// `JsonPlaintext` is): the resolver parses it again when it seals, so
2407+
// a large document is parsed twice. Deliberate: the check runs before
2408+
// any key or keyset load and needs no resolver, and a resolver takes
2409+
// the field's value as a frame, as it does for every target, so it
2410+
// reads the text it is handed.
23972411
if field.field_type == Some(ValueKind::Json) {
23982412
if let Err(error) = super::read_json(value) {
23992413
return Err(Error::Target(TargetError::Json {

0 commit comments

Comments
 (0)