]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Check that the HRPs generated in BOLT 11 `RawHrp` are always valid
authorMatt Corallo <git@bluematt.me>
Thu, 3 Oct 2024 16:54:10 +0000 (16:54 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 3 Oct 2024 17:24:59 +0000 (17:24 +0000)
...in `debug_assertions`.

lightning-invoice/src/lib.rs

index 36370896052f33989ed5a853495f6bcc5a15080d..f696e3545f94e964cd792d54eb28cb192e7275bb 100644 (file)
@@ -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)
        }
 }