Function bytes_to_field

Source
pub fn bytes_to_field<I, F>(bytes: I) -> impl Iterator<Item = F>
where F: PrimeField, I: IntoIterator, I::Item: Borrow<u8>,
Expand description

Deterministic, infallible, invertible iterator adaptor to convert from arbitrary bytes to field elements.

The final field element is padded with zero bytes as needed.

§Example

[doctest ignored because it’s a private module.]

let bytes = [1, 2, 3];
let mut elems_iter = bytes_to_field::<_, Fr254>(bytes);
assert_eq!(elems_iter.next(), Some(Fr254::from(197121u64)));
assert_eq!(elems_iter.next(), None);

§Panics

Panics only under conditions that should be checkable at compile time:

  • The [PrimeField] modulus bit length is too small to hold a u64.
  • The [PrimeField] byte length is too large to fit inside a usize.

If any of the above conditions holds then this function always panics.