MCPcopy
hub / github.com/kopia/kopia / maybeDecryptBlob

Method maybeDecryptBlob

cli/command_blob_show.go:44–82  ·  view source on GitHub ↗
(ctx context.Context, w io.Writer, rep repo.DirectRepository, blobID blob.ID)

Source from the content-addressed store, hash-verified

42}
43
44func (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
84func canDecryptBlob(b blob.ID) bool {
85 switch b[0] {

Callers 1

runMethod · 0.95

Calls 14

CloseMethod · 0.95
BytesMethod · 0.95
DecryptFunction · 0.92
FromSliceFunction · 0.92
JustCopyFunction · 0.92
canDecryptBlobFunction · 0.85
isJSONBlobFunction · 0.85
GetBlobMethod · 0.65
BlobReaderMethod · 0.65
ContentFormatMethod · 0.65
ContentReaderMethod · 0.65
ReaderMethod · 0.65

Tested by

no test coverage detected