MCPcopy Create free account
hub / github.com/WICG/webpackage / AddPayloadIntegrity

Method AddPayloadIntegrity

go/bundle/bundle.go:59–74  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

57//
58// [1] https://wpack-wg.github.io/bundled-responses/draft-ietf-wpack-bundled-responses.html#signatures-section
59func (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.
77func (b *Bundle) Validate() error {

Callers 3

TestSignatureGenerationFunction · 0.95
createTestSignedBundleFunction · 0.95
addSignatureFunction · 0.80

Calls 4

ContentEncodingMethod · 0.80
IntegrityIdentifierMethod · 0.80
MiceEncodingMethod · 0.45
EncodeMethod · 0.45

Tested by 2

TestSignatureGenerationFunction · 0.76
createTestSignedBundleFunction · 0.76