Skip to content

Commit 5627d7c

Browse files
committed
Qualify the BOLT 12 parse error
To avoid a naming conflict in bindings with BOLT 11 parse error, qualify the BOLT 12 parse error type.
1 parent d94227c commit 5627d7c

File tree

7 files changed

+92
-94
lines changed

7 files changed

+92
-94
lines changed

fuzz/src/bech32_parse.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use crate::utils::test_logger;
1111
use core::convert::TryFrom;
12-
use lightning::offers::parse::{Bech32Encode, ParseError};
12+
use lightning::offers::parse::{Bech32Encode, Bolt12ParseError};
1313

1414
#[inline]
1515
pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
@@ -35,8 +35,8 @@ impl AsRef<[u8]> for Bytes {
3535
}
3636

3737
impl TryFrom<Vec<u8>> for Bytes {
38-
type Error = ParseError;
39-
fn try_from(data: Vec<u8>) -> Result<Self, ParseError> {
38+
type Error = Bolt12ParseError;
39+
fn try_from(data: Vec<u8>) -> Result<Self, Bolt12ParseError> {
4040
Ok(Bytes(data))
4141
}
4242
}

lightning/src/offers/invoice.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
//! # fn create_payment_paths() -> Vec<(BlindedPayInfo, BlindedPath)> { unimplemented!() }
3535
//! # fn create_payment_hash() -> PaymentHash { unimplemented!() }
3636
//! #
37-
//! # fn parse_invoice_request(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::ParseError> {
37+
//! # fn parse_invoice_request(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::Bolt12ParseError> {
3838
//! let payment_paths = create_payment_paths();
3939
//! let payment_hash = create_payment_hash();
4040
//! let secp_ctx = Secp256k1::new();
@@ -62,7 +62,7 @@
6262
//! # Ok(())
6363
//! # }
6464
//!
65-
//! # fn parse_refund(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::ParseError> {
65+
//! # fn parse_refund(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::Bolt12ParseError> {
6666
//! # let payment_paths = create_payment_paths();
6767
//! # let payment_hash = create_payment_hash();
6868
//! # let secp_ctx = Secp256k1::new();
@@ -112,7 +112,7 @@ use crate::ln::msgs::DecodeError;
112112
use crate::offers::invoice_request::{INVOICE_REQUEST_PAYER_ID_TYPE, INVOICE_REQUEST_TYPES, IV_BYTES as INVOICE_REQUEST_IV_BYTES, InvoiceRequest, InvoiceRequestContents, InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef};
113113
use crate::offers::merkle::{SignError, SignatureTlvStream, SignatureTlvStreamRef, TlvStream, WithoutSignatures, self};
114114
use crate::offers::offer::{Amount, OFFER_TYPES, OfferTlvStream, OfferTlvStreamRef};
115-
use crate::offers::parse::{ParseError, ParsedMessage, SemanticError};
115+
use crate::offers::parse::{Bolt12ParseError, ParsedMessage, SemanticError};
116116
use crate::offers::payer::{PAYER_METADATA_TYPE, PayerTlvStream, PayerTlvStreamRef};
117117
use crate::offers::refund::{IV_BYTES as REFUND_IV_BYTES, Refund, RefundContents};
118118
use crate::offers::signer;
@@ -728,7 +728,7 @@ impl Writeable for InvoiceContents {
728728
}
729729

730730
impl TryFrom<Vec<u8>> for Bolt12Invoice {
731-
type Error = ParseError;
731+
type Error = Bolt12ParseError;
732732

733733
fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
734734
let parsed_invoice = ParsedMessage::<FullInvoiceTlvStream>::try_from(bytes)?;
@@ -840,7 +840,7 @@ type PartialInvoiceTlvStreamRef<'a> = (
840840
);
841841

842842
impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Bolt12Invoice {
843-
type Error = ParseError;
843+
type Error = Bolt12ParseError;
844844

845845
fn try_from(invoice: ParsedMessage<FullInvoiceTlvStream>) -> Result<Self, Self::Error> {
846846
let ParsedMessage { bytes, tlv_stream } = invoice;
@@ -853,7 +853,7 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Bolt12Invoice {
853853
)?;
854854

855855
let signature = match signature {
856-
None => return Err(ParseError::InvalidSemantics(SemanticError::MissingSignature)),
856+
None => return Err(Bolt12ParseError::InvalidSemantics(SemanticError::MissingSignature)),
857857
Some(signature) => signature,
858858
};
859859
let pubkey = contents.fields().signing_pubkey;
@@ -961,7 +961,7 @@ mod tests {
961961
use crate::offers::invoice_request::InvoiceRequestTlvStreamRef;
962962
use crate::offers::merkle::{SignError, SignatureTlvStreamRef, self};
963963
use crate::offers::offer::{OfferBuilder, OfferTlvStreamRef, Quantity};
964-
use crate::offers::parse::{ParseError, SemanticError};
964+
use crate::offers::parse::{Bolt12ParseError, SemanticError};
965965
use crate::offers::payer::PayerTlvStreamRef;
966966
use crate::offers::refund::RefundBuilder;
967967
use crate::offers::test_utils::*;
@@ -1502,15 +1502,15 @@ mod tests {
15021502

15031503
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
15041504
Ok(_) => panic!("expected error"),
1505-
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPaths)),
1505+
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPaths)),
15061506
}
15071507

15081508
let mut tlv_stream = invoice.as_tlv_stream();
15091509
tlv_stream.3.blindedpay = None;
15101510

15111511
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
15121512
Ok(_) => panic!("expected error"),
1513-
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidPayInfo)),
1513+
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidPayInfo)),
15141514
}
15151515

15161516
let empty_payment_paths = vec![];
@@ -1519,7 +1519,7 @@ mod tests {
15191519

15201520
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
15211521
Ok(_) => panic!("expected error"),
1522-
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPaths)),
1522+
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPaths)),
15231523
}
15241524

15251525
let mut payment_paths = payment_paths();
@@ -1529,7 +1529,7 @@ mod tests {
15291529

15301530
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
15311531
Ok(_) => panic!("expected error"),
1532-
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidPayInfo)),
1532+
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidPayInfo)),
15331533
}
15341534
}
15351535

@@ -1558,7 +1558,7 @@ mod tests {
15581558
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
15591559
Ok(_) => panic!("expected error"),
15601560
Err(e) => {
1561-
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingCreationTime));
1561+
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingCreationTime));
15621562
},
15631563
}
15641564
}
@@ -1610,7 +1610,7 @@ mod tests {
16101610
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
16111611
Ok(_) => panic!("expected error"),
16121612
Err(e) => {
1613-
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPaymentHash));
1613+
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPaymentHash));
16141614
},
16151615
}
16161616
}
@@ -1639,7 +1639,7 @@ mod tests {
16391639

16401640
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
16411641
Ok(_) => panic!("expected error"),
1642-
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingAmount)),
1642+
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingAmount)),
16431643
}
16441644
}
16451645

@@ -1758,7 +1758,7 @@ mod tests {
17581758
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
17591759
Ok(_) => panic!("expected error"),
17601760
Err(e) => {
1761-
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
1761+
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
17621762
},
17631763
}
17641764

@@ -1769,7 +1769,7 @@ mod tests {
17691769
match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
17701770
Ok(_) => panic!("expected error"),
17711771
Err(e) => {
1772-
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidSigningPubkey));
1772+
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidSigningPubkey));
17731773
},
17741774
}
17751775
}
@@ -1790,7 +1790,7 @@ mod tests {
17901790

17911791
match Bolt12Invoice::try_from(buffer) {
17921792
Ok(_) => panic!("expected error"),
1793-
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingSignature)),
1793+
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingSignature)),
17941794
}
17951795
}
17961796

@@ -1814,7 +1814,7 @@ mod tests {
18141814
match Bolt12Invoice::try_from(buffer) {
18151815
Ok(_) => panic!("expected error"),
18161816
Err(e) => {
1817-
assert_eq!(e, ParseError::InvalidSignature(secp256k1::Error::InvalidSignature));
1817+
assert_eq!(e, Bolt12ParseError::InvalidSignature(secp256k1::Error::InvalidSignature));
18181818
},
18191819
}
18201820
}
@@ -1839,7 +1839,7 @@ mod tests {
18391839

18401840
match Bolt12Invoice::try_from(encoded_invoice) {
18411841
Ok(_) => panic!("expected error"),
1842-
Err(e) => assert_eq!(e, ParseError::Decode(DecodeError::InvalidValue)),
1842+
Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::InvalidValue)),
18431843
}
18441844
}
18451845
}

lightning/src/offers/invoice_request.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
//! use lightning::offers::offer::Offer;
3131
//! use lightning::util::ser::Writeable;
3232
//!
33-
//! # fn parse() -> Result<(), lightning::offers::parse::ParseError> {
33+
//! # fn parse() -> Result<(), lightning::offers::parse::Bolt12ParseError> {
3434
//! let secp_ctx = Secp256k1::new();
3535
//! let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32])?);
3636
//! let pubkey = PublicKey::from(keys);
@@ -68,7 +68,7 @@ use crate::ln::msgs::DecodeError;
6868
use crate::offers::invoice::{BlindedPayInfo, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder};
6969
use crate::offers::merkle::{SignError, SignatureTlvStream, SignatureTlvStreamRef, self};
7070
use crate::offers::offer::{Offer, OfferContents, OfferTlvStream, OfferTlvStreamRef};
71-
use crate::offers::parse::{ParseError, ParsedMessage, SemanticError};
71+
use crate::offers::parse::{Bolt12ParseError, ParsedMessage, SemanticError};
7272
use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef};
7373
use crate::offers::signer::{Metadata, MetadataMaterial};
7474
use crate::util::ser::{HighZeroBytesDroppedBigSize, SeekReadable, WithoutLength, Writeable, Writer};
@@ -708,7 +708,7 @@ type PartialInvoiceRequestTlvStreamRef<'a> = (
708708
);
709709

710710
impl TryFrom<Vec<u8>> for InvoiceRequest {
711-
type Error = ParseError;
711+
type Error = Bolt12ParseError;
712712

713713
fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
714714
let invoice_request = ParsedMessage::<FullInvoiceRequestTlvStream>::try_from(bytes)?;
@@ -722,7 +722,7 @@ impl TryFrom<Vec<u8>> for InvoiceRequest {
722722
)?;
723723

724724
let signature = match signature {
725-
None => return Err(ParseError::InvalidSemantics(SemanticError::MissingSignature)),
725+
None => return Err(Bolt12ParseError::InvalidSemantics(SemanticError::MissingSignature)),
726726
Some(signature) => signature,
727727
};
728728
merkle::verify_signature(&signature, SIGNATURE_TAG, &bytes, contents.payer_id)?;
@@ -792,7 +792,7 @@ mod tests {
792792
use crate::offers::invoice::{Bolt12Invoice, SIGNATURE_TAG as INVOICE_SIGNATURE_TAG};
793793
use crate::offers::merkle::{SignError, SignatureTlvStreamRef, self};
794794
use crate::offers::offer::{Amount, OfferBuilder, OfferTlvStreamRef, Quantity};
795-
use crate::offers::parse::{ParseError, SemanticError};
795+
use crate::offers::parse::{Bolt12ParseError, SemanticError};
796796
use crate::offers::payer::PayerTlvStreamRef;
797797
use crate::offers::test_utils::*;
798798
use crate::util::ser::{BigSize, Writeable};
@@ -1438,7 +1438,7 @@ mod tests {
14381438

14391439
match InvoiceRequest::try_from(buffer) {
14401440
Ok(_) => panic!("expected error"),
1441-
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnsupportedChain)),
1441+
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnsupportedChain)),
14421442
}
14431443
}
14441444

@@ -1483,7 +1483,7 @@ mod tests {
14831483

14841484
match InvoiceRequest::try_from(buffer) {
14851485
Ok(_) => panic!("expected error"),
1486-
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingAmount)),
1486+
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingAmount)),
14871487
}
14881488

14891489
let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1499,7 +1499,7 @@ mod tests {
14991499

15001500
match InvoiceRequest::try_from(buffer) {
15011501
Ok(_) => panic!("expected error"),
1502-
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InsufficientAmount)),
1502+
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InsufficientAmount)),
15031503
}
15041504

15051505
let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1515,7 +1515,7 @@ mod tests {
15151515
match InvoiceRequest::try_from(buffer) {
15161516
Ok(_) => panic!("expected error"),
15171517
Err(e) => {
1518-
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnsupportedCurrency));
1518+
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnsupportedCurrency));
15191519
},
15201520
}
15211521

@@ -1533,7 +1533,7 @@ mod tests {
15331533

15341534
match InvoiceRequest::try_from(buffer) {
15351535
Ok(_) => panic!("expected error"),
1536-
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidAmount)),
1536+
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidAmount)),
15371537
}
15381538
}
15391539

@@ -1573,7 +1573,7 @@ mod tests {
15731573
match InvoiceRequest::try_from(buffer) {
15741574
Ok(_) => panic!("expected error"),
15751575
Err(e) => {
1576-
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedQuantity));
1576+
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::UnexpectedQuantity));
15771577
},
15781578
}
15791579

@@ -1609,7 +1609,7 @@ mod tests {
16091609

16101610
match InvoiceRequest::try_from(buffer) {
16111611
Ok(_) => panic!("expected error"),
1612-
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidQuantity)),
1612+
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::InvalidQuantity)),
16131613
}
16141614

16151615
let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1642,7 +1642,7 @@ mod tests {
16421642

16431643
match InvoiceRequest::try_from(buffer) {
16441644
Ok(_) => panic!("expected error"),
1645-
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingQuantity)),
1645+
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingQuantity)),
16461646
}
16471647

16481648
let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1658,7 +1658,7 @@ mod tests {
16581658

16591659
match InvoiceRequest::try_from(buffer) {
16601660
Ok(_) => panic!("expected error"),
1661-
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingQuantity)),
1661+
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingQuantity)),
16621662
}
16631663
}
16641664

@@ -1678,7 +1678,7 @@ mod tests {
16781678
match InvoiceRequest::try_from(buffer) {
16791679
Ok(_) => panic!("expected error"),
16801680
Err(e) => {
1681-
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPayerMetadata));
1681+
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPayerMetadata));
16821682
},
16831683
}
16841684
}
@@ -1698,7 +1698,7 @@ mod tests {
16981698

16991699
match InvoiceRequest::try_from(buffer) {
17001700
Ok(_) => panic!("expected error"),
1701-
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPayerId)),
1701+
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingPayerId)),
17021702
}
17031703
}
17041704

@@ -1718,7 +1718,7 @@ mod tests {
17181718
match InvoiceRequest::try_from(buffer) {
17191719
Ok(_) => panic!("expected error"),
17201720
Err(e) => {
1721-
assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
1721+
assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
17221722
},
17231723
}
17241724
}
@@ -1736,7 +1736,7 @@ mod tests {
17361736

17371737
match InvoiceRequest::try_from(buffer) {
17381738
Ok(_) => panic!("expected error"),
1739-
Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingSignature)),
1739+
Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(SemanticError::MissingSignature)),
17401740
}
17411741
}
17421742

@@ -1757,7 +1757,7 @@ mod tests {
17571757
match InvoiceRequest::try_from(buffer) {
17581758
Ok(_) => panic!("expected error"),
17591759
Err(e) => {
1760-
assert_eq!(e, ParseError::InvalidSignature(secp256k1::Error::InvalidSignature));
1760+
assert_eq!(e, Bolt12ParseError::InvalidSignature(secp256k1::Error::InvalidSignature));
17611761
},
17621762
}
17631763
}
@@ -1782,7 +1782,7 @@ mod tests {
17821782

17831783
match InvoiceRequest::try_from(encoded_invoice_request) {
17841784
Ok(_) => panic!("expected error"),
1785-
Err(e) => assert_eq!(e, ParseError::Decode(DecodeError::InvalidValue)),
1785+
Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::InvalidValue)),
17861786
}
17871787
}
17881788
}

0 commit comments

Comments
 (0)