Skip to content

Commit 6c417ae

Browse files
committed
refactor: address review nits on material example
- name the example's stored size field blobSize, so it reads as the blob's size rather than the plaintext's - keep chunkCountFor above encryptReader to cut diff churn Assisted-by: Claude:claude-opus-5[1m] Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
1 parent b7388ca commit 6c417ae

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

example_material_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ func ExampleDecryptRangeWithMaterial() {
6969
// the blob's exact size.
7070
row := struct {
7171
material fee.BodyMaterial
72-
size int64
72+
blobSize int64
7373
}{material, int64(len(blob))}
7474

7575
// Serving a range later. Nothing here decodes the envelope — the reader is
7676
// built from the stored row, so the only bytes fetched are ciphertext.
7777
src := &countingBlob{blob: bytes.NewReader(blob), headerLen: row.material.HeaderLen}
7878
const off, length = 4, 15
79-
r, err := fee.DecryptRangeWithMaterial(src, row.size, row.material, cek, off, length)
79+
r, err := fee.DecryptRangeWithMaterial(src, row.blobSize, row.material, cek, off, length)
8080
if err != nil {
8181
log.Fatal(err)
8282
}

fee.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,15 @@ func encryptStream(plaintext io.Reader, cek []byte, recipients []Recipient, opts
408408
}, material, nil
409409
}
410410

411+
// chunkCountFor reports how many STREAM chunks a plaintext of nPlain bytes
412+
// produces at the given chunk size. Empty input is one (empty) final chunk.
413+
func chunkCountFor(nPlain, chunkSize int64) int64 {
414+
if nPlain <= 0 {
415+
return 1
416+
}
417+
return (nPlain + chunkSize - 1) / chunkSize
418+
}
419+
411420
// encryptReader is the wire blob [Encrypt] hands back: the encoded envelope
412421
// header, served from memory, followed by the ciphertext the background
413422
// encryption goroutine streams through the pipe.
@@ -423,15 +432,6 @@ func (e *encryptReader) Read(p []byte) (int, error) { return e.body.Read(p) }
423432

424433
func (e *encryptReader) Close() error { return e.pr.Close() }
425434

426-
// chunkCountFor reports how many STREAM chunks a plaintext of nPlain bytes
427-
// produces at the given chunk size. Empty input is one (empty) final chunk.
428-
func chunkCountFor(nPlain, chunkSize int64) int64 {
429-
if nPlain <= 0 {
430-
return 1
431-
}
432-
return (nPlain + chunkSize - 1) / chunkSize
433-
}
434-
435435
// Decrypt recovers the plaintext from a FEE COSE_Encrypt (tag 96) envelope read
436436
// from src.
437437
//

0 commit comments

Comments
 (0)