messageBlock creates a message block from archive data and pre-marshalled metadata
(archiveData []byte, filename string, metadataBytes []byte)
| 289 | |
| 290 | // messageBlock creates a message block from archive data and pre-marshalled metadata |
| 291 | func 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) |
| 321 | func parseMessageBlock(data []byte) (*SumCollection, error) { |
searching dependent graphs…