decodeFieldElement decodes the next input field element by writing its lower 31 bytes into its appropriate place in the output and checking the high order byte is valid. Returns an InvalidFieldElementError if a field element is seen with either of its two high order bits set.
(b []byte, opos, ipos int, output []byte)
| 202 | // appropriate place in the output and checking the high order byte is valid. Returns an |
| 203 | // InvalidFieldElementError if a field element is seen with either of its two high order bits set. |
| 204 | func decodeFieldElement(b []byte, opos, ipos int, output []byte) (byte, int, int, error) { |
| 205 | // two highest order bits of the first byte of each field element should always be 0 |
| 206 | if b[ipos]&0b1100_0000 != 0 { |
| 207 | return 0, 0, 0, fmt.Errorf("%w: field element: %d", ErrBlobInvalidFieldElement, ipos) |
| 208 | } |
| 209 | copy(output[opos:], b[ipos+1:ipos+32]) |
| 210 | return b[ipos], opos + 32, ipos + 32, nil |
| 211 | } |
| 212 | |
| 213 | // reassembleBytes takes the 4x6-bit chunks from encodedByte, reassembles them into 3 bytes of |
| 214 | // output, and places them in their appropriate output positions. |