| 1 | //! Encoding and decoding of zbase32. |
| 2 | //! |
| 3 | //! This is an implementation of the human-oriented base-32 encoding called |
| 4 | //! [zbase32](https://philzimmermann.com/docs/human-oriented-base-32-encoding.txt). |
| 5 | |
| 6 | #![cfg_attr(all(test, feature = "unstable"), feature(test))] |
| 7 | |
| 8 | /// Alphabet used by zbase32 |
| 9 | pub const ALPHABETrust-analyzer cargo zbase32 0.1.2 ALPHABET.: &[u8; 32] = b"ybndrfg8ejkmcpqxot1uwisza345h769"; |
| 10 | |
| 11 | #[rustfmt::skip] |
| 12 | const CONVERSION_TABLErust-analyzer cargo zbase32 0.1.2 CONVERSION_TABLE.: &[Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u8>; 256] = &[ |
| 13 | /* 0 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 14 | /* 5 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 15 | /* 10 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 16 | /* 15 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 17 | /* 20 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 18 | /* 25 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 19 | /* 30 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 20 | /* 35 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 21 | /* 40 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 22 | /* 45 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x12), |
| 23 | /* 50 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x19), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x1a), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x1b), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x1e), |
| 24 | /* 55 */ Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x1d), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x07), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x1f), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 25 | /* 60 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 26 | /* 65 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 27 | /* 70 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 28 | /* 75 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 29 | /* 80 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 30 | /* 85 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 31 | /* 90 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 32 | /* 95 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x18), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x01), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x0c), |
| 33 | /* 100 */ Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x03), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x08), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x05), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x06), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x1c), |
| 34 | /* 105 */ Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x15), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x09), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x0a), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x0b), |
| 35 | /* 110 */ Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x02), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x10), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x0d), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x0e), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x04), |
| 36 | /* 115 */ Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x16), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x11), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x13), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x14), |
| 37 | /* 120 */ Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x0f), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x00), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0x17), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 38 | /* 125 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 39 | /* 130 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 40 | /* 135 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 41 | /* 140 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 42 | /* 145 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 43 | /* 150 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 44 | /* 155 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 45 | /* 160 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 46 | /* 165 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 47 | /* 170 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 48 | /* 175 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 49 | /* 180 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 50 | /* 185 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 51 | /* 190 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 52 | /* 195 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 53 | /* 200 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 54 | /* 205 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 55 | /* 210 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 56 | /* 215 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 57 | /* 220 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 58 | /* 225 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 59 | /* 230 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 60 | /* 235 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 61 | /* 240 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 62 | /* 245 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 63 | /* 250 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 64 | /* 255 */ Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 65 | ]; |
| 66 | |
| 67 | #[inline] |
| 68 | fn value_of_digitrust-analyzer cargo zbase32 0.1.2 value_of_digit().(digit: u8) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<u8, &'static str> { |
| 69 | match CONVERSION_TABLErust-analyzer cargo zbase32 0.1.2 CONVERSION_TABLE.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().digit as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). { |
| 70 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v), |
| 71 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#("not a zbase32 digit"), |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /// Decode first N `bits` of given zbase32 encoded data |
| 76 | /// |
| 77 | /// # Panic |
| 78 | /// |
| 79 | /// Panics if `zbase32` decoded is shorter than N `bits`. |
| 80 | /// |
| 81 | /// # Examples |
| 82 | /// |
| 83 | /// ``` |
| 84 | /// use zbase32; |
| 85 | /// |
| 86 | /// assert_eq!(zbase32::decode(b"o", 1).unwrap(), &[0x80]); |
| 87 | /// ``` |
| 88 | pub fn decoderust-analyzer cargo zbase32 0.1.2 decode().(zbase32: &[u8], bits: u64) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, &'static str> { |
| 89 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(zbase32.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u64 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). 5 >= bits, "zbase32 slice too short"); |
| 90 | #[allow(clippy::cast_possible_truncation)] |
| 91 | let capacity = if bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().0 { |
| 92 | bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div().8 |
| 93 | } else { |
| 94 | bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div().8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().1 |
| 95 | } as usize; |
| 96 | let mut result = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(capacity); |
| 97 | |
| 98 | let mut bits_remaining = bits; |
| 99 | let mut buffer_size: u8 = 0; |
| 100 | let mut buffer: u16 = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][Not]not().0; |
| 101 | for digit in zbase32 { |
| 102 | let value = value_of_digitrust-analyzer cargo zbase32 0.1.2 value_of_digit().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().digit)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 103 | buffer = (buffer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl().5) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitOr<Self>`]bitor().u16::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u16][`From<u8>`]from().(value); |
| 104 | buffer_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign().5; |
| 105 | if bits_remaining rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt().8 && u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u8>`]from().(buffer_size) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge().bits_remaining { |
| 106 | break; |
| 107 | } |
| 108 | if buffer_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge().8 { |
| 109 | #[allow(clippy::cast_possible_truncation)] |
| 110 | let byte = (buffer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<u8>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<u8>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<u8>`]shr().(buffer_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().8)) as u8; |
| 111 | result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(byte); |
| 112 | bits_remaining rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`SubAssign<Self>`]sub_assign().8; |
| 113 | buffer_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`SubAssign<Self>`]sub_assign().8; |
| 114 | } |
| 115 | } |
| 116 | if bits_remaining rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().0 { |
| 117 | #[allow(clippy::cast_possible_truncation)] |
| 118 | let trim_right = buffer_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().bits_remaining as u8; |
| 119 | buffer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`ShrAssign<u8>`]shr_assign().>>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`ShrAssign<u8>`]shr_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`ShrAssign<u8>`]shr_assign().trim_right; |
| 120 | buffer_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`SubAssign<Self>`]sub_assign().trim_right; |
| 121 | #[allow(clippy::cast_possible_truncation)] |
| 122 | let byte = (buffer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<u8>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<u8>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<u8>`]shl().(8_u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().buffer_size)) as u8; |
| 123 | result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(byte); |
| 124 | } |
| 125 | debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(capacity, result.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 126 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(result) |
| 127 | } |
| 128 | |
| 129 | /// Decode given zbase32 encoded string |
| 130 | /// |
| 131 | /// Just like `decode` but doesn't allow decoding with bit precision. |
| 132 | /// |
| 133 | /// This decodes full bytes. For instance, if you have `b"yy"`, you'll get one |
| 134 | /// byte back. `b"yy"` can enode 10 bits (2 * 5) which is truncated at the next |
| 135 | /// lower byte boundary. |
| 136 | /// |
| 137 | /// # Examples |
| 138 | /// |
| 139 | /// ``` |
| 140 | /// use zbase32; |
| 141 | /// |
| 142 | /// assert_eq!(zbase32::decode_full_bytes(b"qb1ze3m1").unwrap(), b"peter"); |
| 143 | /// ``` |
| 144 | #[inline] |
| 145 | pub fn decode_full_bytesrust-analyzer cargo zbase32 0.1.2 decode_full_bytes().(zbase: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, &'static str> { |
| 146 | let size = zbase.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().5; |
| 147 | decoderust-analyzer cargo zbase32 0.1.2 decode().(zbase, size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div().8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().8) |
| 148 | } |
| 149 | |
| 150 | /// Decode first N `bits` of given zbase32 encoded string |
| 151 | /// |
| 152 | /// # Panic |
| 153 | /// |
| 154 | /// Panics if `zbase32` decoded is shorter than N `bits`. |
| 155 | /// |
| 156 | /// # Examples |
| 157 | /// |
| 158 | /// ``` |
| 159 | /// use zbase32; |
| 160 | /// |
| 161 | /// assert_eq!(zbase32::decode_str("o", 1).unwrap(), &[0x80]); |
| 162 | /// ``` |
| 163 | #[inline] |
| 164 | pub fn decode_strrust-analyzer cargo zbase32 0.1.2 decode_str().(zbase32: &str, bits: u64) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, &'static str> { |
| 165 | decoderust-analyzer cargo zbase32 0.1.2 decode().(zbase32.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), bits) |
| 166 | } |
| 167 | |
| 168 | /// Decode given zbase32 encoded string |
| 169 | /// |
| 170 | /// Just like `decode_str` but doesn't allow decoding with bit precision. |
| 171 | /// |
| 172 | /// # Examples |
| 173 | /// |
| 174 | /// ``` |
| 175 | /// use zbase32; |
| 176 | /// |
| 177 | /// assert_eq!(zbase32::decode_full_bytes_str("qb1ze3m1").unwrap(), b"peter"); |
| 178 | /// ``` |
| 179 | #[inline] |
| 180 | pub fn decode_full_bytes_strrust-analyzer cargo zbase32 0.1.2 decode_full_bytes_str().(zbase32: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, &'static str> { |
| 181 | decode_full_bytesrust-analyzer cargo zbase32 0.1.2 decode_full_bytes().(zbase32.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) |
| 182 | } |
| 183 | |
| 184 | /// Encode first N `bits` with zbase32. |
| 185 | /// |
| 186 | /// # Panics |
| 187 | /// |
| 188 | /// Panics if `data` is shorter than N `bits`. |
| 189 | /// |
| 190 | /// # Examples |
| 191 | /// |
| 192 | /// ``` |
| 193 | /// use zbase32; |
| 194 | /// |
| 195 | /// assert_eq!(zbase32::encode(b"testdata", 64), "qt1zg7drcf4gn"); |
| 196 | /// ``` |
| 197 | /// |
| 198 | pub fn encoderust-analyzer cargo zbase32 0.1.2 encode().(data: &[u8], bits: u64) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 199 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u64 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). 8 >= bits, "slice too short"); |
| 200 | #[allow(clippy::cast_possible_truncation)] |
| 201 | let capacity = if bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().0 { |
| 202 | bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div().5 |
| 203 | } else { |
| 204 | bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div().5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().1 |
| 205 | } as usize; |
| 206 | let mut result = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(capacity); |
| 207 | |
| 208 | let mut bits_remaining = bits; |
| 209 | let mut bit_offset: u8 = 16; |
| 210 | let mut remaining = data; |
| 211 | let mut buffer = !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][Not]not().0; |
| 212 | |
| 213 | while bits_remaining rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().0 { |
| 214 | if bit_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge().8 { |
| 215 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((first, others)) = remaining.split_firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_first().() { |
| 216 | buffer = buffer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl().8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitOr<Self>`]bitor().u16::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u16][`From<u8>`]from().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().first); |
| 217 | remaining = others; |
| 218 | bit_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`SubAssign<Self>`]sub_assign().8; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | let unused_bits = 5_u64.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_sub().(bits_remaining); |
| 223 | #[allow(clippy::cast_possible_truncation)] |
| 224 | let index = (buffer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<u8>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<u8>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<u8>`]shr().(unused_bits as u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Add<Self>`]add().16 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().bit_offset) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<u64>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<u64>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<u64>`]shl().unused_bits) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().0x1f; |
| 225 | result.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(ALPHABETrust-analyzer cargo zbase32 0.1.2 ALPHABET.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().index as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 226 | |
| 227 | bit_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`AddAssign<Self>`]add_assign().5; |
| 228 | bits_remaining rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`SubAssign<Self>`]sub_assign().5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().unused_bits; |
| 229 | } |
| 230 | |
| 231 | debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(capacity, result.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 232 | unsafe { Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_uncheckedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_unchecked().(result) } |
| 233 | } |
| 234 | |
| 235 | /// Encode full bytes using zbase32. |
| 236 | /// |
| 237 | /// Just like `encode` but doesn't allow encoding with bit precision. |
| 238 | /// |
| 239 | /// # Examples |
| 240 | /// |
| 241 | /// ``` |
| 242 | /// use zbase32; |
| 243 | /// |
| 244 | /// let data = "Just an arbitrary sentence."; |
| 245 | /// assert_eq!(zbase32::encode_full_bytes(data.as_bytes()), |
| 246 | /// "jj4zg7bycfznyam1cjwzehubqjh1yh5fp34gk5udcwzy"); |
| 247 | /// ``` |
| 248 | #[inline] |
| 249 | pub fn encode_full_bytesrust-analyzer cargo zbase32 0.1.2 encode_full_bytes().(data: &[u8]) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 250 | encoderust-analyzer cargo zbase32 0.1.2 encode().(data, data.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().8) |
| 251 | } |
| 252 | |
| 253 | /// Check if `data` is valid zbase32 encoded bytes |
| 254 | /// |
| 255 | /// # Examples |
| 256 | /// |
| 257 | /// ``` |
| 258 | /// use zbase32; |
| 259 | /// |
| 260 | /// assert!(zbase32::validate(b"y1")); |
| 261 | /// assert!(!zbase32::validate(b"A")); |
| 262 | /// ``` |
| 263 | pub fn validaterust-analyzer cargo zbase32 0.1.2 validate().(data: &[u8]) -> bool { |
| 264 | data.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]all().(|i| value_of_digitrust-analyzer cargo zbase32 0.1.2 value_of_digit().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().i).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()) |
| 265 | } |
| 266 | |
| 267 | /// Check if `data` is valid zbase32 encoded string |
| 268 | /// |
| 269 | /// # Examples |
| 270 | /// |
| 271 | /// ``` |
| 272 | /// use zbase32; |
| 273 | /// |
| 274 | /// assert!(zbase32::validate_str("y1")); |
| 275 | /// assert!(!zbase32::validate_str("A")); |
| 276 | /// ``` |
| 277 | #[inline(always)] |
| 278 | pub fn validate_strrust-analyzer cargo zbase32 0.1.2 validate_str().(data: &str) -> bool { |
| 279 | validaterust-analyzer cargo zbase32 0.1.2 validate().(data.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) |
| 280 | } |
| 281 | |
| 282 | #[cfg(test)] |
| 283 | mod testsrust-analyzer cargo zbase32 0.1.2 tests/ { |
| 284 | #[cfg(feature = "unstable")] |
| 285 | extern crate testrust-analyzer cargo zbase32 0.1.2 tests/test/; |
| 286 | extern crate randrust-analyzer cargo zbase32 0.1.2 tests/rand/; |
| 287 | |
| 288 | use superrust-analyzer cargo zbase32 0.1.2 crate/::*; |
| 289 | #[cfg(feature = "unstable")] |
| 290 | use testsrust-analyzer cargo zbase32 0.1.2 tests/::randrust-analyzer cargo rand 0.6.5 crate/::seqrust-analyzer cargo rand 0.6.5 seq/::SliceRandomrust-analyzer cargo rand 0.6.5 seq/SliceRandom#; |
| 291 | #[cfg(feature = "unstable")] |
| 292 | use testsrust-analyzer cargo zbase32 0.1.2 tests/::randrust-analyzer cargo rand 0.6.5 crate/::Rngrust-analyzer cargo rand 0.6.5 Rng#; |
| 293 | |
| 294 | #[rustfmt::skip] |
| 295 | const TEST_DATArust-analyzer cargo zbase32 0.1.2 tests/TEST_DATA.: &[(u64, &str, &[u8])] = &[ |
| 296 | (0, "", &[]), |
| 297 | (1, "y", &[0x00]), |
| 298 | (1, "o", &[0x80]), |
| 299 | (2, "e", &[0x40]), |
| 300 | (2, "a", &[0xc0]), |
| 301 | (8, "yy", &[0x00]), |
| 302 | (10, "yy", &[0x00, 0x00]), |
| 303 | (10, "on", &[0x80, 0x80]), |
| 304 | (20, "tqre", &[0x8b, 0x88, 0x80]), |
| 305 | (24, "6n9hq", &[0xf0, 0xbf, 0xc7]), |
| 306 | (24, "4t7ye", &[0xd4, 0x7a, 0x04]), |
| 307 | (30, "6im5sd", &[0xf5, 0x57, 0xbb, 0x0c]), |
| 308 | (160, "ybndrfg8ejkmcpqxot1uwisza345h769", &[0x00, 0x44, 0x32, 0x14, 0xc7, 0x42, 0x54, 0xb6, |
| 309 | 0x35, 0xcf, 0x84, 0x65, 0x3a, 0x56, 0xd7, 0xc6, |
| 310 | 0x75, 0xbe, 0x77, 0xdf]) |
| 311 | ]; |
| 312 | |
| 313 | const INVALID_TEST_DATArust-analyzer cargo zbase32 0.1.2 tests/INVALID_TEST_DATA.: &[&str] = &["ybndrfg8ejkmcpqxot1uwisza345H769", "bnâ„•e", "uv", "l"]; |
| 314 | |
| 315 | #[cfg(feature = "unstable")] |
| 316 | const ONE_MIBrust-analyzer cargo zbase32 0.1.2 tests/ONE_MIB.: usize = 1048576; |
| 317 | |
| 318 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 319 | fn test_decoderust-analyzer cargo zbase32 0.1.2 tests/test_decode().() { |
| 320 | for &(bits, zbase32, data) in TEST_DATArust-analyzer cargo zbase32 0.1.2 tests/TEST_DATA. { |
| 321 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(decoderust-analyzer cargo zbase32 0.1.2 decode().(zbase32.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), bits).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), data); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 326 | #[rustfmt::skip] |
| 327 | fn test_decode_full_bytesrust-analyzer cargo zbase32 0.1.2 tests/test_decode_full_bytes().() { |
| 328 | let test_data: &[(&str, &[u8])] = &[ |
| 329 | ("9", &[]), |
| 330 | ("y9", &[0x07]), |
| 331 | ("6n9hq", &[0xf0, 0xbf, 0xc7]), |
| 332 | ("4t7ye", &[0xd4, 0x7a, 0x04]), |
| 333 | ("ybndrfg8ejkmcpqxot1uwisza345h769", &[0x00, 0x44, 0x32, 0x14, 0xc7, 0x42, 0x54, 0xb6, |
| 334 | 0x35, 0xcf, 0x84, 0x65, 0x3a, 0x56, 0xd7, 0xc6, |
| 335 | 0x75, 0xbe, 0x77, 0xdf]) |
| 336 | ]; |
| 337 | |
| 338 | for &(zbase32, data) in test_data { |
| 339 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(decode_full_bytes_strrust-analyzer cargo zbase32 0.1.2 decode_full_bytes_str().(zbase32).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), data); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 344 | fn test_decode_invalid_digitsrust-analyzer cargo zbase32 0.1.2 tests/test_decode_invalid_digits().() { |
| 345 | for string in INVALID_TEST_DATArust-analyzer cargo zbase32 0.1.2 tests/INVALID_TEST_DATA..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 346 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(decoderust-analyzer cargo zbase32 0.1.2 decode().(string.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().(), string.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as u64 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). 5).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 347 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(decode_full_bytesrust-analyzer cargo zbase32 0.1.2 decode_full_bytes().(string.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 352 | fn test_decode_superfluous_bitsrust-analyzer cargo zbase32 0.1.2 tests/test_decode_superfluous_bits().() { |
| 353 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(decoderust-analyzer cargo zbase32 0.1.2 decode().(b"999", 1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), &[0x80]); |
| 354 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(decoderust-analyzer cargo zbase32 0.1.2 decode().(b"4t7yj", 24).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), &[0xd4, 0x7a, 0x04]); |
| 355 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(decoderust-analyzer cargo zbase32 0.1.2 decode().(b"4t7ye9", 25).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), &[0xd4, 0x7a, 0x04, 0x00]); |
| 356 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(decoderust-analyzer cargo zbase32 0.1.2 decode().(b"gyh3", 18).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), &[0x30, 0x39, 0x80]); |
| 357 | } |
| 358 | |
| 359 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 360 | #[should_panic(expected = "zbase32 slice too short")] |
| 361 | fn test_decode_short_slicerust-analyzer cargo zbase32 0.1.2 tests/test_decode_short_slice().() { |
| 362 | decoderust-analyzer cargo zbase32 0.1.2 decode().(b"oyoy", 4 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 363 | } |
| 364 | |
| 365 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 366 | fn test_encoderust-analyzer cargo zbase32 0.1.2 tests/test_encode().() { |
| 367 | for &(bits, zbase32, data) in TEST_DATArust-analyzer cargo zbase32 0.1.2 tests/TEST_DATA. { |
| 368 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(encoderust-analyzer cargo zbase32 0.1.2 encode().(data, bits), zbase32); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 373 | fn test_encode_superfluous_bitsrust-analyzer cargo zbase32 0.1.2 tests/test_encode_superfluous_bits().() { |
| 374 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(encoderust-analyzer cargo zbase32 0.1.2 encode().(&[0xff, 0xff], 1), "o"); |
| 375 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(encoderust-analyzer cargo zbase32 0.1.2 encode().(&[0xd4, 0x7a, 0x04, 0xff], 24), "4t7ye"); |
| 376 | } |
| 377 | |
| 378 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 379 | #[should_panic(expected = "slice too short")] |
| 380 | fn test_encode_short_slicerust-analyzer cargo zbase32 0.1.2 tests/test_encode_short_slice().() { |
| 381 | encoderust-analyzer cargo zbase32 0.1.2 encode().(b"1234", 4 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().1); |
| 382 | } |
| 383 | |
| 384 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 385 | fn test_encode_full_bytesrust-analyzer cargo zbase32 0.1.2 tests/test_encode_full_bytes().() { |
| 386 | for &(_, zbase32, data) in TEST_DATArust-analyzer cargo zbase32 0.1.2 tests/TEST_DATA..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|&&(i, _, _)| i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().0) { |
| 387 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(encode_full_bytesrust-analyzer cargo zbase32 0.1.2 encode_full_bytes().(data), zbase32); |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 392 | fn test_validaterust-analyzer cargo zbase32 0.1.2 tests/test_validate().() { |
| 393 | for &(_, zbase32, _) in TEST_DATArust-analyzer cargo zbase32 0.1.2 tests/TEST_DATA. { |
| 394 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validaterust-analyzer cargo zbase32 0.1.2 validate().(zbase32.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())); |
| 395 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validate_strrust-analyzer cargo zbase32 0.1.2 validate_str().(zbase32)); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 400 | fn test_validate_invalidrust-analyzer cargo zbase32 0.1.2 tests/test_validate_invalid().() { |
| 401 | for string in INVALID_TEST_DATArust-analyzer cargo zbase32 0.1.2 tests/INVALID_TEST_DATA..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 402 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validaterust-analyzer cargo zbase32 0.1.2 validate().(string.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())); |
| 403 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validate_strrust-analyzer cargo zbase32 0.1.2 validate_str().(string)); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 408 | fn test_valid_and_invalid_charsrust-analyzer cargo zbase32 0.1.2 tests/test_valid_and_invalid_chars().() { |
| 409 | for char in 0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#255 { |
| 410 | let bytes = &[char]; |
| 411 | if ALPHABETrust-analyzer cargo zbase32 0.1.2 ALPHABET..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&char) { |
| 412 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ALPHABETrust-analyzer cargo zbase32 0.1.2 ALPHABET.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().value_of_digitrust-analyzer cargo zbase32 0.1.2 value_of_digit().(char).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., char); |
| 413 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(encoderust-analyzer cargo zbase32 0.1.2 encode().(&decoderust-analyzer cargo zbase32 0.1.2 decode().(bytes, 5).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), 5).as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().(), bytes); |
| 414 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(validaterust-analyzer cargo zbase32 0.1.2 validate().(bytes)); |
| 415 | } else { |
| 416 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(value_of_digitrust-analyzer cargo zbase32 0.1.2 value_of_digit().(char).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 417 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(decode_full_bytesrust-analyzer cargo zbase32 0.1.2 decode_full_bytes().(bytes).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 418 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().validaterust-analyzer cargo zbase32 0.1.2 validate().(bytes)); |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | #[cfg(feature = "unstable")] |
| 424 | #[benchrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/bench:] |
| 425 | fn decode_one_mibrust-analyzer cargo zbase32 0.1.2 tests/decode_one_mib().(b: &mut testrust-analyzer cargo test https://github.com/rust-lang/rust/library/test crate/::Bencherrust-analyzer cargo test https://github.com/rust-lang/rust/library/test bench/Bencher#) { |
| 426 | let data = random_encoded_datarust-analyzer cargo zbase32 0.1.2 tests/random_encoded_data().(ONE_MIBrust-analyzer cargo zbase32 0.1.2 tests/ONE_MIB.); |
| 427 | b.iterrust-analyzer cargo test https://github.com/rust-lang/rust/library/test bench/impl#[Bencher]iter().(|| decode_full_bytesrust-analyzer cargo zbase32 0.1.2 decode_full_bytes().(&data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()) |
| 428 | } |
| 429 | |
| 430 | #[cfg(feature = "unstable")] |
| 431 | #[benchrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/bench:] |
| 432 | fn encode_one_mibrust-analyzer cargo zbase32 0.1.2 tests/encode_one_mib().(b: &mut testrust-analyzer cargo test https://github.com/rust-lang/rust/library/test crate/::Bencherrust-analyzer cargo test https://github.com/rust-lang/rust/library/test bench/Bencher#) { |
| 433 | let data = random_datarust-analyzer cargo zbase32 0.1.2 tests/random_data().(ONE_MIBrust-analyzer cargo zbase32 0.1.2 tests/ONE_MIB.); |
| 434 | b.iterrust-analyzer cargo test https://github.com/rust-lang/rust/library/test bench/impl#[Bencher]iter().(|| encode_full_bytesrust-analyzer cargo zbase32 0.1.2 encode_full_bytes().(&data)) |
| 435 | } |
| 436 | |
| 437 | #[cfg(feature = "unstable")] |
| 438 | #[benchrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/bench:] |
| 439 | fn decode_five_bytesrust-analyzer cargo zbase32 0.1.2 tests/decode_five_bytes().(b: &mut testrust-analyzer cargo test https://github.com/rust-lang/rust/library/test crate/::Bencherrust-analyzer cargo test https://github.com/rust-lang/rust/library/test bench/Bencher#) { |
| 440 | let data = random_encoded_datarust-analyzer cargo zbase32 0.1.2 tests/random_encoded_data().(5); |
| 441 | b.iterrust-analyzer cargo test https://github.com/rust-lang/rust/library/test bench/impl#[Bencher]iter().(|| decode_full_bytesrust-analyzer cargo zbase32 0.1.2 decode_full_bytes().(&data).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()) |
| 442 | } |
| 443 | |
| 444 | #[cfg(feature = "unstable")] |
| 445 | #[benchrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/bench:] |
| 446 | fn encode_five_bytesrust-analyzer cargo zbase32 0.1.2 tests/encode_five_bytes().(b: &mut testrust-analyzer cargo test https://github.com/rust-lang/rust/library/test crate/::Bencherrust-analyzer cargo test https://github.com/rust-lang/rust/library/test bench/Bencher#) { |
| 447 | let data = random_datarust-analyzer cargo zbase32 0.1.2 tests/random_data().(5); |
| 448 | b.iterrust-analyzer cargo test https://github.com/rust-lang/rust/library/test bench/impl#[Bencher]iter().(|| encode_full_bytesrust-analyzer cargo zbase32 0.1.2 encode_full_bytes().(&data)) |
| 449 | } |
| 450 | |
| 451 | #[cfg(feature = "unstable")] |
| 452 | #[benchrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/bench:] |
| 453 | fn validate_one_mibrust-analyzer cargo zbase32 0.1.2 tests/validate_one_mib().(b: &mut testrust-analyzer cargo test https://github.com/rust-lang/rust/library/test crate/::Bencherrust-analyzer cargo test https://github.com/rust-lang/rust/library/test bench/Bencher#) { |
| 454 | let data = random_encoded_datarust-analyzer cargo zbase32 0.1.2 tests/random_encoded_data().(ONE_MIBrust-analyzer cargo zbase32 0.1.2 tests/ONE_MIB.); |
| 455 | b.iterrust-analyzer cargo test https://github.com/rust-lang/rust/library/test bench/impl#[Bencher]iter().(|| validaterust-analyzer cargo zbase32 0.1.2 validate().(&data)) |
| 456 | } |
| 457 | |
| 458 | #[cfg(feature = "unstable")] |
| 459 | fn random_datarust-analyzer cargo zbase32 0.1.2 tests/random_data().(bytes: usize) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> { |
| 460 | let mut data = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0_u8; bytes]; |
| 461 | randrust-analyzer cargo rand 0.6.5 crate/::thread_rngrust-analyzer cargo rand 0.6.5 rngs/thread/thread_rng().().fillrust-analyzer cargo rand 0.6.5 Rng#fill().(&mut data[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().); |
| 462 | data |
| 463 | } |
| 464 | |
| 465 | #[cfg(feature = "unstable")] |
| 466 | fn random_encoded_datarust-analyzer cargo zbase32 0.1.2 tests/random_encoded_data().(bytes: usize) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> { |
| 467 | let mut gen = randrust-analyzer cargo rand 0.6.5 crate/::thread_rngrust-analyzer cargo rand 0.6.5 rngs/thread/thread_rng().(); |
| 468 | (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().5) |
| 469 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|_| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().ALPHABETrust-analyzer cargo zbase32 0.1.2 ALPHABET..chooserust-analyzer cargo rand 0.6.5 seq/impl#[`[T]`][SliceRandom]choose().(&mut gen).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()) |
| 470 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().() |
| 471 | } |
| 472 | } |