Move lightning-invoice deser errors to lib.rs instead of `pub use` 2022-04-bindings-invoice-ders
authorMatt Corallo <git@bluematt.me>
Mon, 4 Apr 2022 02:51:22 +0000 (02:51 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 4 Apr 2022 13:19:41 +0000 (13:19 +0000)
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.

lightning-invoice/src/de.rs
lightning-invoice/src/lib.rs

index 9e96849a274c24d9ba1a08845b8d69622c75a4ff..5de2b038e8b2d29a25df42705d5d7d378009a7fb 100644 (file)
@@ -23,8 +23,8 @@ use secp256k1::recovery::{RecoveryId, RecoverableSignature};
 use secp256k1::key::PublicKey;
 
 use super::{Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiry, Fallback, PayeePubKey, InvoiceSignature, PositiveTimestamp,
-       SemanticError, PrivateRoute, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawInvoice, constants, SignedRawInvoice,
-       RawDataPart, InvoiceFeatures};
+       SemanticError, PrivateRoute, ParseError, ParseOrSemanticError, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawInvoice,
+       constants, SignedRawInvoice, RawDataPart, InvoiceFeatures};
 
 use self::hrp_sm::parse_hrp;
 
@@ -619,46 +619,6 @@ impl FromBase32 for PrivateRoute {
        }
 }
 
-/// Errors that indicate what is wrong with the invoice. They have some granularity for debug
-/// reasons, but should generally result in an "invalid BOLT11 invoice" message for the user.
-#[allow(missing_docs)]
-#[derive(PartialEq, Debug, Clone)]
-pub enum ParseError {
-       Bech32Error(bech32::Error),
-       ParseAmountError(ParseIntError),
-       MalformedSignature(secp256k1::Error),
-       BadPrefix,
-       UnknownCurrency,
-       UnknownSiPrefix,
-       MalformedHRP,
-       TooShortDataPart,
-       UnexpectedEndOfTaggedFields,
-       DescriptionDecodeError(str::Utf8Error),
-       PaddingError,
-       IntegerOverflowError,
-       InvalidSegWitProgramLength,
-       InvalidPubKeyHashLength,
-       InvalidScriptHashLength,
-       InvalidRecoveryId,
-       InvalidSliceLength(String),
-
-       /// Not an error, but used internally to signal that a part of the invoice should be ignored
-       /// according to BOLT11
-       Skip,
-}
-
-/// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
-/// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
-/// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
-#[derive(PartialEq, Debug, Clone)]
-pub enum ParseOrSemanticError {
-       /// The invoice couldn't be decoded
-       ParseError(ParseError),
-
-       /// The invoice could be decoded but violates the BOLT11 standard
-       SemanticError(::SemanticError),
-}
-
 impl Display for ParseError {
        fn fmt(&self, f: &mut Formatter) -> fmt::Result {
                match *self {
index 1dd7123a486d1077f1295b7655b1fac497cfb57f..5784607dde937b85fa384ed65a630d7af1d3ca3a 100644 (file)
@@ -53,9 +53,11 @@ use secp256k1::recovery::RecoverableSignature;
 
 use core::fmt::{Display, Formatter, self};
 use core::iter::FilterMap;
+use core::num::ParseIntError;
 use core::ops::Deref;
 use core::slice::Iter;
 use core::time::Duration;
+use core::str;
 
 mod de;
 mod ser;
@@ -86,7 +88,45 @@ mod sync {
 #[cfg(not(feature = "std"))]
 mod sync;
 
-pub use de::{ParseError, ParseOrSemanticError};
+/// Errors that indicate what is wrong with the invoice. They have some granularity for debug
+/// reasons, but should generally result in an "invalid BOLT11 invoice" message for the user.
+#[allow(missing_docs)]
+#[derive(PartialEq, Debug, Clone)]
+pub enum ParseError {
+       Bech32Error(bech32::Error),
+       ParseAmountError(ParseIntError),
+       MalformedSignature(secp256k1::Error),
+       BadPrefix,
+       UnknownCurrency,
+       UnknownSiPrefix,
+       MalformedHRP,
+       TooShortDataPart,
+       UnexpectedEndOfTaggedFields,
+       DescriptionDecodeError(str::Utf8Error),
+       PaddingError,
+       IntegerOverflowError,
+       InvalidSegWitProgramLength,
+       InvalidPubKeyHashLength,
+       InvalidScriptHashLength,
+       InvalidRecoveryId,
+       InvalidSliceLength(String),
+
+       /// Not an error, but used internally to signal that a part of the invoice should be ignored
+       /// according to BOLT11
+       Skip,
+}
+
+/// Indicates that something went wrong while parsing or validating the invoice. Parsing errors
+/// should be mostly seen as opaque and are only there for debugging reasons. Semantic errors
+/// like wrong signatures, missing fields etc. could mean that someone tampered with the invoice.
+#[derive(PartialEq, Debug, Clone)]
+pub enum ParseOrSemanticError {
+       /// The invoice couldn't be decoded
+       ParseError(ParseError),
+
+       /// The invoice could be decoded but violates the BOLT11 standard
+       SemanticError(::SemanticError),
+}
 
 /// The number of bits used to represent timestamps as defined in BOLT 11.
 const TIMESTAMP_BITS: usize = 35;