Skip to content

Commit 02295a3

Browse files
committed
Add UTF-8 encoding option to the envelope document and proto.
Signed-off-by: Zhenyu (Adam) Wu <[email protected]>
1 parent 046695d commit 02295a3

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

envelope.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ the following form, called the "JSON envelope":
1818

1919
```json
2020
{
21-
"payload": "<Base64(SERIALIZED_BODY)>",
21+
// Arbitrary binary data can be encode in base64.
22+
"payload": "<Base64(byte sequence)>",
23+
// If the SERIALIZED_BODY is a text string,
24+
// it can *instead* be encoded in UTF-8.
25+
// "payloadUtf8": "<Utf-8 encoded text>",
26+
2227
"payloadType": "<PAYLOAD_TYPE>",
2328
"signatures": [{
2429
"keyid": "<KEYID>",
@@ -29,9 +34,20 @@ the following form, called the "JSON envelope":
2934

3035
See [Protocol](protocol.md) for a definition of parameters and functions.
3136

32-
Base64() is [Base64 encoding](https://tools.ietf.org/html/rfc4648), transforming
33-
a byte sequence to a unicode string. Either standard or URL-safe encoding is
34-
allowed.
37+
Arbitrary binary data can be encode in [Base64](https://tools.ietf.org/html/rfc4648),
38+
as a unicode string and enclosed in the envelope using the `payload` key.
39+
Either standard or URL-safe encoding is allowed.
40+
41+
However, if the serialized payload body is a text string, it can *instead* be
42+
encoded in [UTF-8](https://tools.ietf.org/html/rfc3629) and enclosed in the
43+
envelope using the `payloadUtf8` key. The UTF-8 encoding has a lower overhead
44+
than Base64 for texts, and is more friendly for compression algorithms.
45+
46+
Note:
47+
48+
1. Use either the `payload` or `payloadUtf8` key in an envelope, not both;
49+
2. The choice of payload encoding does not impact
50+
[the signing or the signatures](protocol.md#signature-definition).
3551

3652
### Multiple signatures
3753

@@ -41,6 +57,7 @@ envelopes with individual signatures.
4157
```json
4258
{
4359
"payload": "<Base64(SERIALIZED_BODY)>",
60+
// Or "payloadUtf8": "<Utf-8 encoded text>",
4461
"payloadType": "<PAYLOAD_TYPE>",
4562
"signatures": [{
4663
"keyid": "<KEYID_1>",
@@ -54,8 +71,8 @@ envelopes with individual signatures.
5471

5572
### Parsing rules
5673

57-
* The following fields are REQUIRED and MUST be set, even if empty: `payload`,
58-
`payloadType`, `signature`, `signature.sig`.
74+
* The following fields are REQUIRED and MUST be set, even if empty:
75+
one of (`payload`, `payloadUtf8`), `payloadType`, `signature`, `signature.sig`.
5976
* The following fields are OPTIONAL and MAY be unset: `signature.keyid`.
6077
An unset field MUST be treated the same as set-but-empty.
6178
* Producers, or future versions of the spec, MAY add additional fields.

envelope.proto

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ package io.intoto;
44

55
// An authenticated message of arbitrary type.
66
message Envelope {
7-
// Message to be signed. (In JSON, this is encoded as base64.)
7+
// Message to be signed.
88
// REQUIRED.
9-
bytes payload = 1;
10-
9+
oneof payload_encoding {
10+
// Raw bytes. In JSON, this is encoded as base64.
11+
bytes payload = 1;
12+
// Unicode string, where the signed byte stream is the UTF-8 encoding. In JSON, this is a regular unicode string.
13+
string payloadUtf8 = 4;
14+
}
15+
1116
// String unambiguously identifying how to interpret payload.
1217
// REQUIRED.
1318
string payloadType = 2;

0 commit comments

Comments
 (0)