bitbelay_providers/
lib.rs1use clap::ValueEnum;
4
5pub mod ascii;
6pub mod numeric;
7
8const SHORT_BITS: usize = 3;
10
11const MEDIUM_BITS: usize = 6;
13
14const LONG_BITS: usize = 12;
16
17pub trait Provider: std::fmt::Debug {
19 fn name(&self) -> &str;
21
22 fn provide(&mut self, n: usize) -> Vec<&[u8]>;
24
25 fn bytes_per_input(&mut self) -> usize;
27}
28
29#[derive(Clone, Debug, Default, ValueEnum)]
31pub enum AvailableProviders {
32 #[clap(name = "ascii-alphanumeric")]
34 #[default]
35 ASCIIAlphanumeric,
36
37 #[clap(name = "ascii-alphanumeric-long")]
39 ASCIIAlphanumericLong,
40
41 #[clap(name = "ascii-alphanumeric-short")]
43 ASCIIAlphanumericShort,
44
45 #[clap(name = "u64")]
47 U64,
48
49 #[clap(name = "u64-long")]
51 U64Long,
52
53 #[clap(name = "u64-short")]
55 U64Short,
56}
57
58impl std::fmt::Display for AvailableProviders {
59 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
60 match self {
61 AvailableProviders::ASCIIAlphanumeric => write!(f, "ascii-alphanumeric"),
62 AvailableProviders::ASCIIAlphanumericLong => write!(f, "ascii-alphanumeric-long"),
63 AvailableProviders::ASCIIAlphanumericShort => write!(f, "ascii-alphanumeric-short"),
64 AvailableProviders::U64 => write!(f, "u64"),
65 AvailableProviders::U64Long => write!(f, "u64-long"),
66 AvailableProviders::U64Short => write!(f, "u64-short"),
67 }
68 }
69}
70
71impl From<AvailableProviders> for Box<dyn Provider> {
72 fn from(provider: AvailableProviders) -> Self {
73 match provider {
74 AvailableProviders::ASCIIAlphanumeric => {
76 Box::new(ascii::AlphanumericProvider::new(1 << MEDIUM_BITS))
77 }
78 AvailableProviders::ASCIIAlphanumericLong => {
79 Box::new(ascii::AlphanumericProvider::new(1 << LONG_BITS))
80 }
81 AvailableProviders::ASCIIAlphanumericShort => {
82 Box::new(ascii::AlphanumericProvider::new(1 << SHORT_BITS))
83 }
84
85 AvailableProviders::U64 => {
87 Box::new(numeric::Unsigned64BitProvider::new(1 << MEDIUM_BITS))
88 }
89 AvailableProviders::U64Long => {
90 Box::new(numeric::Unsigned64BitProvider::new(1 << LONG_BITS))
91 }
92 AvailableProviders::U64Short => {
93 Box::new(numeric::Unsigned64BitProvider::new(1 << SHORT_BITS))
94 }
95 }
96 }
97}