MCPcopy
hub / github.com/helm/helm / messageBlock

Function messageBlock

pkg/provenance/sign.go:291–318  ·  view source on GitHub ↗

messageBlock creates a message block from archive data and pre-marshalled metadata

(archiveData []byte, filename string, metadataBytes []byte)

Source from the content-addressed store, hash-verified

289
290// messageBlock creates a message block from archive data and pre-marshalled metadata
291func messageBlock(archiveData []byte, filename string, metadataBytes []byte) (*bytes.Buffer, error) {
292 // Checksum the archive data
293 chash, err := Digest(bytes.NewBuffer(archiveData))
294 if err != nil {
295 return nil, err
296 }
297
298 sums := &SumCollection{
299 Files: map[string]string{
300 filename: "sha256:" + chash,
301 },
302 }
303
304 // Buffer the metadata + checksums YAML file
305 // FIXME: YAML uses ---\n as a file start indicator, but this is not legal in a PGP
306 // clearsign block. So we use ...\n, which is the YAML document end marker.
307 // http://yaml.org/spec/1.2/spec.html#id2800168
308 b := bytes.NewBuffer(metadataBytes)
309 b.WriteString("\n...\n")
310
311 data, err := yaml.Marshal(sums)
312 if err != nil {
313 return nil, err
314 }
315 b.Write(data)
316
317 return b, nil
318}
319
320// parseMessageBlock parses a message block and returns only checksums (metadata ignored like upstream)
321func parseMessageBlock(data []byte) (*SumCollection, error) {

Callers 2

ClearSignMethod · 0.85
TestMessageBlockFunction · 0.85

Calls 2

DigestFunction · 0.85
WriteMethod · 0.45

Tested by 1

TestMessageBlockFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…