From: Matt Corallo Date: Thu, 3 Oct 2024 16:54:10 +0000 (+0000) Subject: Check that the HRPs generated in BOLT 11 `RawHrp` are always valid X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=c5658f6cc2cfa6eee2a45d206b08933d30f1a275;p=rust-lightning Check that the HRPs generated in BOLT 11 `RawHrp` are always valid ...in `debug_assertions`. --- diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index 363708960..f696e3545 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -313,6 +313,7 @@ impl RawHrp { pub fn to_hrp(&self) -> bech32::Hrp { let hrp_str = self.to_string(); let s = core::str::from_utf8(&hrp_str.as_bytes()).expect("HRP bytes should be ASCII"); + debug_assert!(bech32::Hrp::parse(s).is_ok(), "We should always build BIP 173-valid HRPs"); bech32::Hrp::parse_unchecked(s) } }