Skip to content

Commit 44c0374

Browse files
authored
Merge pull request #1409 from TheBlueMatt/2022-04-bindings-invoice-ders
Move lightning-invoice deser errors to lib.rs instead of `pub use`
2 parents 0a0f87c + ce5a9f5 commit 44c0374

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

lightning-invoice/src/de.rs

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use secp256k1::recovery::{RecoveryId, RecoverableSignature};
2323
use secp256k1::key::PublicKey;
2424

2525
use super::{Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiry, Fallback, PayeePubKey, InvoiceSignature, PositiveTimestamp,
26-
SemanticError, PrivateRoute, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawInvoice, constants, SignedRawInvoice,
27-
RawDataPart, InvoiceFeatures};
26+
SemanticError, PrivateRoute, ParseError, ParseOrSemanticError, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawInvoice,
27+
constants, SignedRawInvoice, RawDataPart, InvoiceFeatures};
2828

2929
use self::hrp_sm::parse_hrp;
3030

@@ -619,46 +619,6 @@ impl FromBase32 for PrivateRoute {
619619
}
620620
}
621621

622-
/// Errors that indicate what is wrong with the invoice. They have some granularity for debug
623-
/// reasons, but should generally result in an "invalid BOLT11 invoice" message for the user.
624-
#[allow(missing_docs)]
625-
#[derive(PartialEq, Debug, Clone)]
626-
pub enum ParseError {
627-
Bech32Error(bech32::Error),
628-
ParseAmountError(ParseIntError),
629-
MalformedSignature(secp256k1::Error),
630-
BadPrefix,
631-
UnknownCurrency,
632-
UnknownSiPrefix,
633-
MalformedHRP,
634-
TooShortDataPart,
635-
UnexpectedEndOfTaggedFields,
636-
DescriptionDecodeError(str::Utf8Error),
637-
PaddingError,
638-
IntegerOverflowError,
639-
InvalidSegWitProgramLength,
640-
InvalidPubKeyHashLength,
641-
InvalidScriptHashLength,
642-
InvalidRecoveryId,
643-
InvalidSliceLength(String),
644-
645-
/// Not an error, but used internally to signal that a part of the invoice should be ignored
646-
/// according to BOLT11
647-
Skip,
648-
}
649-
650-
/// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
651-
/// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
652-
/// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
653-
#[derive(PartialEq, Debug, Clone)]
654-
pub enum ParseOrSemanticError {
655-
/// The invoice couldn't be decoded
656-
ParseError(ParseError),
657-
658-
/// The invoice could be decoded but violates the BOLT11 standard
659-
SemanticError(::SemanticError),
660-
}
661-
662622
impl Display for ParseError {
663623
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
664624
match *self {

lightning-invoice/src/lib.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ use secp256k1::recovery::RecoverableSignature;
5353

5454
use core::fmt::{Display, Formatter, self};
5555
use core::iter::FilterMap;
56+
use core::num::ParseIntError;
5657
use core::ops::Deref;
5758
use core::slice::Iter;
5859
use core::time::Duration;
60+
use core::str;
5961

6062
mod de;
6163
mod ser;
@@ -86,7 +88,45 @@ mod sync {
8688
#[cfg(not(feature = "std"))]
8789
mod sync;
8890

89-
pub use de::{ParseError, ParseOrSemanticError};
91+
/// Errors that indicate what is wrong with the invoice. They have some granularity for debug
92+
/// reasons, but should generally result in an "invalid BOLT11 invoice" message for the user.
93+
#[allow(missing_docs)]
94+
#[derive(PartialEq, Debug, Clone)]
95+
pub enum ParseError {
96+
Bech32Error(bech32::Error),
97+
ParseAmountError(ParseIntError),
98+
MalformedSignature(secp256k1::Error),
99+
BadPrefix,
100+
UnknownCurrency,
101+
UnknownSiPrefix,
102+
MalformedHRP,
103+
TooShortDataPart,
104+
UnexpectedEndOfTaggedFields,
105+
DescriptionDecodeError(str::Utf8Error),
106+
PaddingError,
107+
IntegerOverflowError,
108+
InvalidSegWitProgramLength,
109+
InvalidPubKeyHashLength,
110+
InvalidScriptHashLength,
111+
InvalidRecoveryId,
112+
InvalidSliceLength(String),
113+
114+
/// Not an error, but used internally to signal that a part of the invoice should be ignored
115+
/// according to BOLT11
116+
Skip,
117+
}
118+
119+
/// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
120+
/// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
121+
/// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
122+
#[derive(PartialEq, Debug, Clone)]
123+
pub enum ParseOrSemanticError {
124+
/// The invoice couldn't be decoded
125+
ParseError(ParseError),
126+
127+
/// The invoice could be decoded but violates the BOLT11 standard
128+
SemanticError(::SemanticError),
129+
}
90130

91131
/// The number of bits used to represent timestamps as defined in BOLT 11.
92132
const TIMESTAMP_BITS: usize = 35;

0 commit comments

Comments
 (0)