Skip to content

Commit 68ea0fa

Browse files
committed
refactor: rename error to ErrInvalidDescriptor
Assisted-by: Claude:claude-fable-5 Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>"
1 parent 46a967b commit 68ea0fa

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

descriptor.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"github.com/filecoin-project/go-fee/aesstream"
99
)
1010

11-
// ErrIncompleteDescriptor means a [BodyDescriptor] is missing a field, or carries
11+
// ErrInvalidDescriptor means a [BodyDescriptor] is missing a field, or carries
1212
// one that cannot describe a FEE body — a value that could not decrypt anything.
13-
var ErrIncompleteDescriptor = errors.New("fee: incomplete body descriptor")
13+
var ErrInvalidDescriptor = errors.New("fee: invalid body descriptor")
1414

1515
// BodyDescriptor is everything a range decrypt needs from a FEE envelope, so a
1616
// caller that cached it can serve a byte range without fetching or decoding the
@@ -64,22 +64,22 @@ type BodyDescriptor struct {
6464
// range read could use.
6565
//
6666
// [DecryptRangeWithCEK] calls it when desc is non-nil, so a bad value fails
67-
// there with [ErrIncompleteDescriptor] rather than as an authentication error
67+
// there with [ErrInvalidDescriptor] rather than as an authentication error
6868
// further down.
6969
func (m BodyDescriptor) Validate() error {
7070
if m.HeaderLen <= 0 {
71-
return fmt.Errorf("%w: header length %d is not positive", ErrIncompleteDescriptor, m.HeaderLen)
71+
return fmt.Errorf("%w: header length %d is not positive", ErrInvalidDescriptor, m.HeaderLen)
7272
}
7373
if len(m.BaseNonce) != aesstream.BaseNonceSize {
7474
return fmt.Errorf("%w: base nonce is %d bytes, want %d",
75-
ErrIncompleteDescriptor, len(m.BaseNonce), aesstream.BaseNonceSize)
75+
ErrInvalidDescriptor, len(m.BaseNonce), aesstream.BaseNonceSize)
7676
}
7777
if m.ChunkSize < aesstream.MinChunkSize || m.ChunkSize > aesstream.MaxChunkSize {
7878
return fmt.Errorf("%w: chunk size %d out of range [%d, %d]",
79-
ErrIncompleteDescriptor, m.ChunkSize, aesstream.MinChunkSize, aesstream.MaxChunkSize)
79+
ErrInvalidDescriptor, m.ChunkSize, aesstream.MinChunkSize, aesstream.MaxChunkSize)
8080
}
8181
if len(m.AAD) == 0 {
82-
return fmt.Errorf("%w: missing AAD", ErrIncompleteDescriptor)
82+
return fmt.Errorf("%w: missing AAD", ErrInvalidDescriptor)
8383
}
8484
return nil
8585
}
@@ -90,7 +90,7 @@ func (m BodyDescriptor) Validate() error {
9090
// suffix range ("bytes=-N" is off = size-N) from cached metadata alone.
9191
//
9292
// blobSize is the whole stored object, envelope included, exactly as passed to
93-
// [DecryptRangeWithCEK] when desc is non-nil. It reports [ErrIncompleteDescriptor]
93+
// [DecryptRangeWithCEK] when desc is non-nil. It reports [ErrInvalidDescriptor]
9494
// for an unusable m, and [aesstream.ErrCiphertextSize] if blobSize cannot
9595
// describe a FEE blob at this header length and chunk size.
9696
func (m BodyDescriptor) PlaintextSize(blobSize int64) (int64, error) {

descriptor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,13 @@ func TestBodyDescriptorValidate(t *testing.T) {
288288
t.Run(name, func(t *testing.T) {
289289
m := good
290290
mutate(&m)
291-
require.ErrorIs(t, m.Validate(), fee.ErrIncompleteDescriptor)
291+
require.ErrorIs(t, m.Validate(), fee.ErrInvalidDescriptor)
292292

293293
// The range entry point rejects it up front for the same reason,
294294
// rather than letting it fail as an authentication error later.
295295
_, err := fee.DecryptRangeWithCEK(bytes.NewReader([]byte("blob")), 4096,
296296
make([]byte, aesstream.KeySize), 0, 10, &m)
297-
require.ErrorIs(t, err, fee.ErrIncompleteDescriptor)
297+
require.ErrorIs(t, err, fee.ErrInvalidDescriptor)
298298
})
299299
}
300300
}

range.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func DecryptRange(blob io.ReaderAt, blobSize int64, unwrap RecipientUnwrapper, o
174174
// entirely; the only bytes then fetched from blob are the ciphertext chunks the
175175
// range overlaps. The descriptor is cloned before use, so later caller mutation
176176
// cannot affect the decryptor built from it. A malformed descriptor is rejected
177-
// up front with [ErrIncompleteDescriptor]; a well-formed but stale or wrong one
177+
// up front with [ErrInvalidDescriptor]; a well-formed but stale or wrong one
178178
// fails when read as [aesstream.ErrCorrupted], not as plausible plaintext.
179179
//
180180
// blobSize is the size of the whole stored blob, envelope included, exactly as

0 commit comments

Comments
 (0)