arnaucube
arnaucube/NovaPublic Self-hosted repository
Nova/examples/ecdsa/utils.rs
examples/ecdsa/utils.rsRaw
 1#[derive(Debug)]
 2pub struct BitIterator<E> {
 3  t: E,
 4  n: usize,
 5}
 6
 7impl<E: AsRef<[u64]>> BitIterator<E> {
 8  pub fn new(t: E) -> Self {
 9    let n = t.as_ref().len() * 64;
10
11    BitIterator { t, n }
12  }
13}
14
15impl<E: AsRef<[u64]>> Iterator for BitIterator<E> {
16  type Item = bool;
17
18  fn next(&mut self) -> Option<bool> {
19    if self.n == 0 {
20      None
21    } else {
22      self.n -= 1;
23      let part = self.n / 64;
24      let bit = self.n - (64 * part);
25
26      Some(self.t.as_ref()[part] & (1 << bit) > 0)
27    }
28  }
29}