| 1 | extern crate randrust-analyzer cargo zbase32 0.1.2 common/rand/; |
| 2 | extern crate quickcheckrust-analyzer cargo zbase32 0.1.2 common/quickcheck/; |
| 3 | extern crate zbase32rust-analyzer cargo zbase32 0.1.2 common/zbase32/; |
| 4 | |
| 5 | use selfrust-analyzer cargo zbase32 0.1.2 common/::quickcheckrust-analyzer cargo quickcheck 0.7.2 crate/::{Arbitraryrust-analyzer cargo quickcheck 0.7.2 arbitrary/Arbitrary#, Genrust-analyzer cargo quickcheck 0.7.2 arbitrary/Gen#}; |
| 6 | use selfrust-analyzer cargo zbase32 0.1.2 common/::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#; |
| 7 | use selfrust-analyzer cargo zbase32 0.1.2 common/::randrust-analyzer cargo rand 0.6.5 crate/::Rngrust-analyzer cargo rand 0.6.5 Rng#; |
| 8 | |
| 9 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 10 | pub struct ZBaseEncodedDatarust-analyzer cargo zbase32 0.1.2 common/ZBaseEncodedData#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>); |
| 11 | |
| 12 | impl Arbitraryrust-analyzer cargo quickcheck 0.7.2 arbitrary/Arbitrary# for ZBaseEncodedDatarust-analyzer cargo zbase32 0.1.2 common/ZBaseEncodedData# { |
| 13 | fn arbitraryrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData][Arbitrary]arbitrary().<G: Genrust-analyzer cargo quickcheck 0.7.2 arbitrary/Gen#>(g: &mut G) -> Selfrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData][Arbitrary] { |
| 14 | let len = g.gen_rangerust-analyzer cargo rand 0.6.5 Rng#gen_range().(0, 256); |
| 15 | let content = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#len) |
| 16 | .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().zbase32rust-analyzer cargo zbase32 0.1.2 crate/::ALPHABETrust-analyzer cargo zbase32 0.1.2 ALPHABET..chooserust-analyzer cargo rand 0.6.5 seq/impl#[`[T]`][SliceRandom]choose().(g).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()) |
| 17 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 18 | ZBaseEncodedDatarust-analyzer cargo zbase32 0.1.2 common/ZBaseEncodedData#(content) |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | impl ZBaseEncodedDatarust-analyzer cargo zbase32 0.1.2 common/ZBaseEncodedData# { |
| 23 | pub fn as_bytesrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData]as_bytes().(&self) -> &[u8] { |
| 24 | &self.0rust-analyzer cargo zbase32 0.1.2 common/ZBaseEncodedData#0. |
| 25 | } |
| 26 | |
| 27 | #[allow(unused)] |
| 28 | pub fn into_bytesrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData]into_bytes().(self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> { |
| 29 | self.0rust-analyzer cargo zbase32 0.1.2 common/ZBaseEncodedData#0. |
| 30 | } |
| 31 | |
| 32 | pub fn lenrust-analyzer cargo zbase32 0.1.2 common/impl#[ZBaseEncodedData]len().(&self) -> usize { |
| 33 | self.0rust-analyzer cargo zbase32 0.1.2 common/ZBaseEncodedData#0..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | pub fn rand_bit_lengthrust-analyzer cargo zbase32 0.1.2 common/rand_bit_length().(units: usize, bits_per_unit: u64) -> u64 { |
| 38 | let bits = if units rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 39 | randrust-analyzer cargo rand 0.6.5 crate/::thread_rngrust-analyzer cargo rand 0.6.5 rngs/thread/thread_rng().().gen_rangerust-analyzer cargo rand 0.6.5 Rng#gen_range().(0, units 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().bits_per_unit) |
| 40 | } else { |
| 41 | 0 |
| 42 | }; |
| 43 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("random bit length: {}", bits); |
| 44 | bits |
| 45 | } |