Skip to content

Commit

Permalink
Move JSONFormatToInvalidSignatureError to an unconditionally-included…
Browse files Browse the repository at this point in the history
… file

otherwise:
> % go build -tags ' containers_image_fulcio_stub containers_image_rekor_stub' ./...
> # github.com/containers/image/v5/signature/internal
> signature/internal/sigstore_payload.go:83:9: undefined: JSONFormatToInvalidSignatureError

Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Nov 28, 2024
1 parent 1a28c1b commit 204ca8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
9 changes: 9 additions & 0 deletions signature/internal/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ func (err InvalidSignatureError) Error() string {
func NewInvalidSignatureError(msg string) InvalidSignatureError {
return InvalidSignatureError{msg: msg}
}

// JSONFormatToInvalidSignatureError converts JSONFormatError to InvalidSignatureError.
// All other errors are returned as is.
func JSONFormatToInvalidSignatureError(err error) error {
if formatErr, ok := err.(JSONFormatError); ok {
err = NewInvalidSignatureError(formatErr.Error())
}
return err
}
9 changes: 0 additions & 9 deletions signature/internal/rekor_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ type UntrustedRekorPayload struct {
// A compile-time check that UntrustedRekorSET implements json.Unmarshaler
var _ json.Unmarshaler = (*UntrustedRekorSET)(nil)

// JSONFormatToInvalidSignatureError converts JSONFormatError to InvalidSignatureError.
// All other errors are returned as is.
func JSONFormatToInvalidSignatureError(err error) error {
if formatErr, ok := err.(JSONFormatError); ok {
err = NewInvalidSignatureError(formatErr.Error())
}
return err
}

// UnmarshalJSON implements the json.Unmarshaler interface
func (s *UntrustedRekorSET) UnmarshalJSON(data []byte) error {
return JSONFormatToInvalidSignatureError(s.strictUnmarshalJSON(data))
Expand Down

0 comments on commit 204ca8b

Please sign in to comment.