From 784b52bdead835f5b5856b253e4f6bb4b397be8f Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 4 Jun 2026 21:59:48 +0200 Subject: [PATCH] restic: add PackBlob interface and implement it on PackedBlob The PackBlob interface will allow hiding details from the public interface, in particular, the offset of a blob within a pack file. --- internal/restic/blob.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/internal/restic/blob.go b/internal/restic/blob.go index ba9277aac..8d1e8a720 100644 --- a/internal/restic/blob.go +++ b/internal/restic/blob.go @@ -41,12 +41,42 @@ func (b Blobs) Sort() { }) } +// PackBlob is one index entry for a blob in a pack file. +// The interface intentionally omits the offset at which a blob is stored in the pack. +// This ensures that pack file internals are not leaked. +type PackBlob interface { + PackID() ID + Handle() BlobHandle + // CiphertextLength is the encrypted size stored in the pack. + CiphertextLength() uint + // PlaintextLength is the size after decryption/decompression. + PlaintextLength() uint + IsCompressed() bool +} + // PackedBlob is a blob stored within a file. type PackedBlob struct { Blob PackID ID } +type packBlob struct { + PackedBlob +} + +func (pb packBlob) PackID() ID { return pb.PackedBlob.PackID } + +func (pb packBlob) Handle() BlobHandle { return pb.BlobHandle } + +func (pb packBlob) CiphertextLength() uint { return pb.Length } + +func (pb packBlob) PlaintextLength() uint { return pb.DataLength() } + +func (pb packBlob) IsCompressed() bool { return pb.Blob.IsCompressed() } + +// AsPackBlob returns a PackBlob view of a PackedBlob. +func AsPackBlob(pb PackedBlob) PackBlob { return packBlob{pb} } + // BlobHandle identifies a blob of a given type. type BlobHandle struct { ID ID