Skip to content

Commit

Permalink
Include digest in RD validation error message
Browse files Browse the repository at this point in the history
Signed-off-by: Marcela Melara <marcela.melara@intel.com>
  • Loading branch information
marcelamelara committed Apr 8, 2024
1 parent 9fd2ef1 commit dfaabea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions go/v1/resource_descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ func (d *ResourceDescriptor) Validate() error {
hashBytes, err := hex.DecodeString(digest)

if err != nil {
return fmt.Errorf("%w: %s", ErrInvalidDigestEncoding, alg)
return fmt.Errorf("%w (%s: %s)", ErrInvalidDigestEncoding, alg, digest)
}

// check the length of the digest
if len(hashBytes) != size {
return fmt.Errorf("%w: %s (got %d bytes, want %d bytes", ErrIncorrectDigestLength, alg, len(hashBytes), size)
return fmt.Errorf("%w: got %d bytes, want %d bytes (%s: %s)", ErrIncorrectDigestLength, len(hashBytes), size, alg, digest)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions go/v1/resource_descriptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestBadResourceDescriptorDigestEncoding(t *testing.T) {
assert.NoError(t, err, "Error during JSON unmarshalling")

err = got.Validate()
assert.ErrorIs(t, err, ErrInvalidDigestEncoding, "created ResourceDescriptor with invalid digest encoding")
assert.ErrorIs(t, err, ErrInvalidDigestEncoding, "did not get expected error when validating ResourceDescriptor with invalid digest encoding")
}

func TestBadResourceDescriptorDigestLength(t *testing.T) {
Expand All @@ -99,5 +99,5 @@ func TestBadResourceDescriptorDigestLength(t *testing.T) {
assert.NoError(t, err, "Error during JSON unmarshalling")

err = got.Validate()
assert.ErrorIs(t, err, ErrIncorrectDigestLength, "created ResourceDescriptor with incorrect digest length")
assert.ErrorIs(t, err, ErrIncorrectDigestLength, "did not get expected error when validating ResourceDescriptor with incorrect digest length")
}

0 comments on commit dfaabea

Please sign in to comment.