1 extern crate lightning_invoice;
4 use lightning_invoice::RawDataPart;
5 use bech32::{FromBase32, ToBase32, u5};
7 fn do_test(data: &[u8]) {
8 let bech32 = data.iter().map(|x| u5::try_from_u8(x % 32).unwrap()).collect::<Vec<_>>();
9 let invoice = match RawDataPart::from_base32(&bech32) {
10 Ok(invoice) => invoice,
14 // Our encoding is not worse than the input
15 assert!(invoice.to_base32().len() <= bech32.len());
17 // Our serialization is loss-less
19 RawDataPart::from_base32(&invoice.to_base32()).expect("faild parsing out own encoding"),
24 #[cfg(feature = "afl")]
25 #[macro_use] extern crate afl;
26 #[cfg(feature = "afl")]
33 #[cfg(feature = "honggfuzz")]
34 #[macro_use] extern crate honggfuzz;
35 #[cfg(feature = "honggfuzz")]
46 fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
48 for (idx, c) in hex.as_bytes().iter().filter(|&&c| c != b'\n').enumerate() {
51 b'A'..=b'F' => b |= c - b'A' + 10,
52 b'a'..=b'f' => b |= c - b'a' + 10,
53 b'0'..=b'9' => b |= c - b'0',
54 _ => panic!("Bad hex"),
64 fn duplicate_crash() {
65 let mut a = Vec::new();
66 extend_vec_from_hex("000000", &mut a);