AddPayloadIntegrity encodes the exchange's payload with Merkle Integrity content encoding, and adds `Content-Encoding` and `Digest` response headers. It returns an identifier for the "payload-integrity-header" field of the "resource-integrity" structure. [1] [1] https://wpack-wg.github.io/bundled-r
(ver version.Version, recordSize int)
| 57 | // |
| 58 | // [1] https://wpack-wg.github.io/bundled-responses/draft-ietf-wpack-bundled-responses.html#signatures-section |
| 59 | func (e *Exchange) AddPayloadIntegrity(ver version.Version, recordSize int) (string, error) { |
| 60 | if e.Response.Header.Get("Digest") != "" { |
| 61 | return "", errors.New("bundle: the exchange already has the Digest: header") |
| 62 | } |
| 63 | |
| 64 | encoding := ver.MiceEncoding() |
| 65 | var buf bytes.Buffer |
| 66 | digest, err := encoding.Encode(&buf, e.Response.Body, recordSize) |
| 67 | if err != nil { |
| 68 | return "", err |
| 69 | } |
| 70 | e.Response.Body = buf.Bytes() |
| 71 | e.Response.Header.Add("Content-Encoding", encoding.ContentEncoding()) |
| 72 | e.Response.Header.Add("Digest", digest) |
| 73 | return encoding.IntegrityIdentifier(), nil |
| 74 | } |
| 75 | |
| 76 | // Validate performs basic sanity checks on the bundle. |
| 77 | func (b *Bundle) Validate() error { |