(ctx context.Context, w io.Writer, rep repo.DirectRepository, blobID blob.ID)
| 42 | } |
| 43 | |
| 44 | func (c *commandBlobShow) maybeDecryptBlob(ctx context.Context, w io.Writer, rep repo.DirectRepository, blobID blob.ID) error { |
| 45 | var ( |
| 46 | d gather.WriteBuffer |
| 47 | b gather.Bytes |
| 48 | ) |
| 49 | |
| 50 | if err := rep.BlobReader().GetBlob(ctx, blobID, 0, -1, &d); err != nil { |
| 51 | return errors.Wrap(err, "error reading blob") |
| 52 | } |
| 53 | |
| 54 | b = d.Bytes() |
| 55 | |
| 56 | if c.blobShowDecrypt && canDecryptBlob(blobID) { |
| 57 | var tmp gather.WriteBuffer |
| 58 | defer tmp.Close() |
| 59 | |
| 60 | if err := blobcrypto.Decrypt(rep.ContentReader().ContentFormat(), b, blobID, &tmp); err != nil { |
| 61 | return errors.Wrap(err, "error decrypting blob") |
| 62 | } |
| 63 | |
| 64 | b = tmp.Bytes() |
| 65 | } |
| 66 | |
| 67 | if isJSONBlob(blobID) { |
| 68 | var buf bytes.Buffer |
| 69 | |
| 70 | if err := json.Indent(&buf, b.ToByteSlice(), "", " "); err != nil { |
| 71 | return errors.Wrap(err, "invalid JSON") |
| 72 | } |
| 73 | |
| 74 | b = gather.FromSlice(buf.Bytes()) |
| 75 | } |
| 76 | |
| 77 | if err := iocopy.JustCopy(w, b.Reader()); err != nil { |
| 78 | return errors.Wrap(err, "error copying data") |
| 79 | } |
| 80 | |
| 81 | return nil |
| 82 | } |
| 83 | |
| 84 | func canDecryptBlob(b blob.ID) bool { |
| 85 | switch b[0] { |
no test coverage detected