Skip to content

Commit 03cafce

Browse files
committed
Move lightning-invoice deser errors to lib.rs instead of pub use
Having public types in a private module is somewhat awkward from a readability standpoint, but, more importantly, the bindings logic has a relatively rough go of converting them - it doesn't implement `pub use` as its "implement this function" logic is all within the context of a module. We'd need to keep a set of re-exported things to implement them when parsing modules...or we could just move two enums from `de.rs` to `lib.rs` here, which is substantially less work.
1 parent 0a0f87c commit 03cafce

File tree

2 files changed

+44
-43
lines changed

2 files changed

+44
-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: 42 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,46 @@ mod sync {
8688
#[cfg(not(feature = "std"))]
8789
mod sync;
8890

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

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

0 commit comments

Comments
 (0)