Skip to content

Commit

Permalink
zpay32: Switch to ErrInvalidFieldLength sentinel
Browse files Browse the repository at this point in the history
This switches the applicable error to use an exported sentinel error so
that it is more testable.
  • Loading branch information
matheusd committed Nov 26, 2019
1 parent cb2b8b4 commit 85f9c03
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion zpay32/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ var (

// ErrInvoiceTooLarge is returned when an invoice exceeds maxInvoiceLength.
ErrInvoiceTooLarge = errors.New("invoice is too large")

// ErrInvalidFieldLength is returned when a tagged field was specified
// with a length larger than the left over bytes of the data field.
ErrInvalidFieldLength = errors.New("invalid field length")
)

// MessageSigner is passed to the Encode method to provide a signature
Expand Down Expand Up @@ -617,7 +621,7 @@ func parseTaggedFields(invoice *Invoice, fields []byte, net *chaincfg.Params) er
// If we don't have enough field data left to read this length,
// return error.
if len(fields) < index+3+int(dataLength) {
return fmt.Errorf("invalid field length")
return ErrInvalidFieldLength
}
base32Data := fields[index+3 : index+3+int(dataLength)]

Expand Down

0 comments on commit 85f9c03

Please sign in to comment.