Fix bug with bitfield validation

This commit is contained in:
Paul Hauner 2018-09-28 15:37:53 +09:30
parent debc642b50
commit 05fe231e41
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C

View File

@ -45,15 +45,6 @@ pub enum AttestationValidationError {
DBError(String),
}
fn bytes_for_bits(bits: usize) -> usize {
(bits.saturating_sub(1) / 8) + 1
}
fn any_of_last_n_bits_are_set(byte: u8, n: usize) -> bool {
let shift = 8_u16.saturating_sub(n as u16);
((!0 << shift) & u16::from(byte)) > 0
}
pub fn validate_attestation<T>(a: &AttestationRecord,
block_slot: u64,
cycle_length: u8,
@ -164,6 +155,20 @@ pub fn validate_attestation<T>(a: &AttestationRecord,
Ok(voted_hashmap)
}
fn bytes_for_bits(bits: usize) -> usize {
(bits.saturating_sub(1) / 8) + 1
}
fn any_of_last_n_bits_are_set(byte: u8, n: usize) -> bool {
for i in 0..n {
let mask = 0_u8 >> 8_usize - i as usize;
if byte & mask > 0 {
return true
}
}
false
}
impl From<ParentHashesError> for AttestationValidationError {
fn from(e: ParentHashesError) -> Self {
match e {