X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Foffers%2Fparse.rs;h=c48d745a9ffd365ecf09800bc6b6bd24d6e988b5;hb=e3dea2c3c7099c63d569b8912b9633aa733be19a;hp=5b4eec841028e4054941c7f65fe64ed02c549a5d;hpb=5fc4abc5cd756ec6e7a0ea4af1abddbb58308d49;p=rust-lightning diff --git a/lightning/src/offers/parse.rs b/lightning/src/offers/parse.rs index 5b4eec84..c48d745a 100644 --- a/lightning/src/offers/parse.rs +++ b/lightning/src/offers/parse.rs @@ -9,13 +9,12 @@ //! Parsing and formatting for bech32 message encoding. -use bitcoin::bech32; use bitcoin::secp256k1; -use core::convert::TryFrom; use crate::io; use crate::ln::msgs::DecodeError; use crate::util::ser::SeekReadable; +#[allow(unused_imports)] use crate::prelude::*; #[cfg(not(fuzzing))] @@ -25,12 +24,11 @@ pub(super) use sealed::Bech32Encode; pub use sealed::Bech32Encode; mod sealed { - use bitcoin::bech32; - use bitcoin::bech32::{FromBase32, ToBase32}; - use core::convert::TryFrom; + use bech32::{FromBase32, ToBase32}; use core::fmt; use super::Bolt12ParseError; + #[allow(unused_imports)] use crate::prelude::*; /// Indicates a message can be encoded using bech32. @@ -183,12 +181,16 @@ pub enum Bolt12SemanticError { DuplicatePaymentId, /// Blinded paths were expected but were missing. MissingPaths, + /// Blinded paths were provided but were not expected. + UnexpectedPaths, /// The blinded payinfo given does not match the number of blinded path hops. InvalidPayInfo, /// An invoice creation time was expected but was missing. MissingCreationTime, /// An invoice payment hash was expected but was missing. MissingPaymentHash, + /// An invoice payment hash was provided but was not expected. + UnexpectedPaymentHash, /// A signature was expected but was missing. MissingSignature, } @@ -218,10 +220,8 @@ impl From for Bolt12ParseError { } #[cfg(test)] -mod tests { +mod bolt12_tests { use super::Bolt12ParseError; - use bitcoin::bech32; - use crate::ln::msgs::DecodeError; use crate::offers::offer::Offer; #[test] @@ -236,10 +236,16 @@ mod tests { #[test] fn parses_bech32_encoded_offers() { let offers = [ - // BOLT 12 test vectors + // A complete string is valid "lno1pqps7sjqpgtyzm3qv4uxzmtsd3jjqer9wd3hy6tsw35k7msjzfpy7nz5yqcnygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxg", + + // + can join anywhere "l+no1pqps7sjqpgtyzm3qv4uxzmtsd3jjqer9wd3hy6tsw35k7msjzfpy7nz5yqcnygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxg", + + // Multiple + can join "lno1pqps7sjqpgt+yzm3qv4uxzmtsd3jjqer9wd3hy6tsw3+5k7msjzfpy7nz5yqcn+ygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd+5xvxg", + + // + can be followed by whitespace "lno1pqps7sjqpgt+ yzm3qv4uxzmtsd3jjqer9wd3hy6tsw3+ 5k7msjzfpy7nz5yqcn+\nygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd+\r\n 5xvxg", ]; for encoded_offer in &offers { @@ -252,7 +258,7 @@ mod tests { #[test] fn fails_parsing_bech32_encoded_offers_with_invalid_continuations() { let offers = [ - // BOLT 12 test vectors + // + must be surrounded by bech32 characters "lno1pqps7sjqpgtyzm3qv4uxzmtsd3jjqer9wd3hy6tsw35k7msjzfpy7nz5yqcnygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxg+", "lno1pqps7sjqpgtyzm3qv4uxzmtsd3jjqer9wd3hy6tsw35k7msjzfpy7nz5yqcnygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxg+ ", "+lno1pqps7sjqpgtyzm3qv4uxzmtsd3jjqer9wd3hy6tsw35k7msjzfpy7nz5yqcnygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxg", @@ -266,6 +272,13 @@ mod tests { } } } +} + +#[cfg(test)] +mod tests { + use super::Bolt12ParseError; + use crate::ln::msgs::DecodeError; + use crate::offers::offer::Offer; #[test] fn fails_parsing_bech32_encoded_offer_with_invalid_hrp() {