Skip to content

Commit 7da1b51

Browse files
committed
Upgrade bech32 dependency, bech32 serialization improvements
1 parent c2d16fa commit 7da1b51

File tree

13 files changed

+621
-519
lines changed

13 files changed

+621
-519
lines changed

fuzz/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ stdin_fuzz = []
2121
lightning = { path = "../lightning", features = ["regex", "_test_utils"] }
2222
lightning-invoice = { path = "../lightning-invoice" }
2323
lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync" }
24-
bech32 = "0.9.1"
24+
bech32 = "0.11.0"
2525
bitcoin = { version = "0.32.2", features = ["secp-lowmemory"] }
2626

2727
afl = { version = "0.12", optional = true }

fuzz/src/bolt11_deser.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
// licenses.
99

1010
use crate::utils::test_logger;
11-
use bech32::{u5, FromBase32, ToBase32};
11+
use bech32::Fe32;
1212
use bitcoin::secp256k1::{Secp256k1, SecretKey};
1313
use lightning_invoice::{
14-
Bolt11Invoice, RawBolt11Invoice, RawDataPart, RawHrp, RawTaggedField, TaggedField,
14+
Base32Iterable, Bolt11Invoice, FromBase32, RawBolt11Invoice, RawDataPart, RawHrp,
15+
RawTaggedField, TaggedField,
1516
};
1617
use std::str::FromStr;
1718

@@ -25,19 +26,19 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
2526
Err(_) => return,
2627
};
2728
let bech32 =
28-
data.iter().skip(hrp_len).map(|x| u5::try_from_u8(x % 32).unwrap()).collect::<Vec<_>>();
29+
data.iter().skip(hrp_len).map(|x| Fe32::try_from(x % 32).unwrap()).collect::<Vec<_>>();
2930
let invoice_data = match RawDataPart::from_base32(&bech32) {
3031
Ok(invoice) => invoice,
3132
Err(_) => return,
3233
};
3334

35+
let invoice_data_base32 = invoice_data.fe_iter().collect::<Vec<_>>();
3436
// Our data encoding is not worse than the input
35-
assert!(invoice_data.to_base32().len() <= bech32.len());
37+
assert!(invoice_data_base32.len() <= bech32.len());
3638

3739
// Our data serialization is loss-less
3840
assert_eq!(
39-
RawDataPart::from_base32(&invoice_data.to_base32())
40-
.expect("faild parsing out own encoding"),
41+
RawDataPart::from_base32(&invoice_data_base32).expect("faild parsing out own encoding"),
4142
invoice_data
4243
);
4344

lightning-invoice/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ rustdoc-args = ["--cfg", "docsrs"]
1818
std = []
1919

2020
[dependencies]
21-
bech32 = { version = "0.9.1", default-features = false }
21+
bech32 = { version = "0.11.0", default-features = false }
2222
lightning-types = { version = "0.1.0", path = "../lightning-types", default-features = false }
2323
serde = { version = "1.0.118", optional = true }
2424
bitcoin = { version = "0.32.2", default-features = false, features = ["secp-recovery"] }

0 commit comments

Comments
 (0)