+// base32 decoder and tests stolen (transliterated) from Bitcoin Core
+// Copyright (c) 2012-2019 The Bitcoin Core developers
+// Distributed under the MIT software license, see
+// http://www.opensource.org/licenses/mit-license.php.
+fn decode_base32(inp: &[u8]) -> Option<Vec<u8>> {
+ let decode32_table: [i8; 256] = [
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 0, 1, 2,
+ 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
+ 23, 24, 25, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+ ];
+
+ let mut ret = Vec::with_capacity((inp.len() * 5) / 8);
+
+ let mut acc: u16 = 0;
+ let mut bits: u8 = 0;
+ for i in inp {
+ if *i == '=' as u8 { break; }
+ let codepoint = decode32_table[*i as usize];
+ if codepoint < 0 { return None; }
+ acc = ((acc << 5) | codepoint as u16) & ((1 << (8 + 5 - 1)) - 1);
+ bits += 5;
+ while bits >= 8 {
+ bits -= 8;
+ ret.push((acc >> bits) as u8);
+ }
+ }
+ Some(ret)
+}
+
+#[test]
+fn test_decode_base32() {
+ let tests_in = ["","f","fo","foo","foob","fooba","foobar"];
+ let tests_out = ["","my======","mzxq====","mzxw6===","mzxw6yq=","mzxw6ytb","mzxw6ytboi======"];
+ for (inp, out) in tests_in.iter().zip(tests_out.iter()) {
+ assert_eq!(&decode_base32(out.as_bytes()).unwrap()[..], inp.as_bytes());
+ }
+ // My seednode's onion addr:
+ assert_eq!(decode_base32("nkf5e6b7pl4jfd4a".as_bytes()).unwrap()[..],[0x6a, 0x8b, 0xd2, 0x78, 0x3f, 0x7a, 0xf8, 0x92, 0x8f, 0x80]);
+}
+
+pub fn read(store: &'static Store, printer: &'static Printer, bgp_client: Arc<BGPClient>) {