zpay32: Switch to ErrInvalidFieldLength sentinel

This switches the applicable error to use an exported sentinel error so
that it is more testable.
This commit is contained in:
Matheus Degiovani 2019-11-26 13:13:06 -03:00
parent cb2b8b4513
commit 85f9c03797

@ -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
@ -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)]