From 85f9c03797344d8bab5b8bc448e9ee3518d17766 Mon Sep 17 00:00:00 2001 From: Matheus Degiovani Date: Tue, 26 Nov 2019 13:13:06 -0300 Subject: [PATCH] zpay32: Switch to ErrInvalidFieldLength sentinel This switches the applicable error to use an exported sentinel error so that it is more testable. --- zpay32/invoice.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zpay32/invoice.go b/zpay32/invoice.go index d36b31ca..9a9fde33 100644 --- a/zpay32/invoice.go +++ b/zpay32/invoice.go @@ -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)]