Skip to content
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

Add request generating and response parsing sections #2

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
35 changes: 18 additions & 17 deletions draft-ietf-protected-audience-key-value-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,28 +320,30 @@ Each key group is expected to have exactly one tag from the following list:

### Generating a Request {#request-generate}

This section describes how the client MAY form and serialize request messages in order to fetch values from the Trusted Key Value server.
This section describes how the client MAY form and serialize request messages in order to fetch values from the Trusted Key Value server.

This algorithm takes as input an [HPKE] `public key` and its associated `key id`, a `metadata` map for global configuration, where both keys and values are strings, and a list of `signals`, each of which is a map, from a list of strings to a list of strings.
This algorithm takes as input an [HPKE] `public key` and its associated `key id`, a `metadata` map for global configuration, where both keys and values are strings, and a `compression groups` list, each of which is a map, from key `"partitions"` to value `partitions` as a list of maps.
xtlsheep marked this conversation as resolved.
Show resolved Hide resolved

The output is an [HPKE] ciphertext encrypted `request` and a context `request context`.

1. Let `request map` be an empty map.
1. Let `compression group id` be 0.
1. Let `partitions` be an empty array.
1. For each `signal` in `signals`:
1. Let `partition` be an empty map.
1. Set `partition["id"]` to 0.
1. Set `partition["compressionGroupId"]` to `compression group id`.
1. Let `compression group id` increase by 1.
1. For each `group` in `compression groups`:
1. For each `partition` in `compression groups["partitions"]:
xtlsheep marked this conversation as resolved.
Show resolved Hide resolved
1. Let `p` be an empty map.
1. Set `p["compressionGroupId"]` to `group[compressionGroupId"]`.
1. Set `p["id"]` to `partition["id"]`.
1. Let `arguments` be an empty array.
1. For each `tags` → `data` in `signal`:
1. For each `key` → `value` in `partition`:
1. If `key` equals "metadata":
1. Set `p["metadata"]` to `partition["metadata"].
1. Otherwise:
1. Let `argument` be an empty map.
1. Set `argument["tags"]` to `tags`.
1. Set `argument["tags"]` to `key`.
1. Set `argument["data"]` to `data`.
1. Insert `argument` into `arguments`.
1. Set `partition["arguments"]` to `arguments`.
1. Insert `partition` into `partitions`.
1. Set `p["arguments"]` to `arguments`.
1. Insert `p` into `partitions`.
1. Set `request map["metadata"]` to `metadata`.
1. Set `request map["partitions"]` to `partitions`.
1. Set `request map["acceptCompression"]` to `["none", "gzip"]`.
Expand Down Expand Up @@ -623,7 +625,7 @@ The output is a `result` map, where the keys are strings, and the values are map

1. Use `request context` as the context to decrypt `encrypted response` and obtain `framed response`, returning failure if decryption fails.
1. Remove and extract the first 5 bytes from `framed response` as the framing header (described in {{framing}}), removing them from `framed response`.
1. If `framing header`'s `Version` field is not 0 or 2, return failure.
1. If `framing header`'s `Compression` field is not 0 or 2, return failure.
1. Let `length` be equal to the `framing header`'s `Size` field.
1. If `length` is greater than the length of the remaining bytes in `framed response`, return failure.
1. Take the first `length` remaining bytes in `framed response` as `serialized response`, discarding the rest.
Expand All @@ -634,10 +636,7 @@ The output is a `result` map, where the keys are strings, and the values are map
1. For each `group` in `response["compressionGroups"]`:
1. If `group` is not a map, return failure.
1. If `group["content"]` does not exist, return failure.
1. If `framing header`'s `Version` field is 0:
1. Set `serialized content` to `group["content"]`.
1. Otherwise:
1. [GZIP] decompress the `group["content"]` to `serialized content`, returning failure if decompression fails.
1. Set `serialized content` to the result of decompressing `group["content"]` according to the compression algorithm specified in the `framing header`'s `Compression` field, returning failure if decompression fails.
1. [CBOR] decode the `serialized content` into `content`, returning failure if decoding fails.
1. If `content` is not an array, return failure.
1. For each `partition` in `content`:
Expand All @@ -656,6 +655,8 @@ The output is a `result` map, where the keys are strings, and the values are map
1. Set `key value[key]` to `value["value"]`.
1. Set `result[output["tags"]]` to `key value`.
1. If `partition["dataVersion"]` exists, Set `result["dataVersion"]` to `partition["dataVersion"]`.
1. Set `result["compressionGroupId"]` to `group["compressionGroupId"]`.
1. Set `result["id"]` to `partition["id"]`.
1. Append `result` to `results`.
1. Return `results`.

Expand Down