fn check_binary(cursor: &mut Cursor<&[u8]>) -> BinaryLoaderResult<u8> {
    let mut magic = [0u8; BinaryConstants::LIBRA_MAGIC_SIZE];
    if let Ok(count) = cursor.read(&mut magic) {
        if count != BinaryConstants::LIBRA_MAGIC_SIZE || magic != BinaryConstants::LIBRA_MAGIC {
            return Err(VMStatus::new(StatusCode::BAD_MAGIC));
        }
    } else {
        return Err(
            VMStatus::new(StatusCode::MALFORMED).with_message("Bad binary header".to_string())
        );
    }
    let major_ver = 1u8;
    let minor_ver = 0u8;
    if let Ok(ver) = cursor.read_u8() {
        if ver != major_ver {
            return Err(VMStatus::new(StatusCode::UNKNOWN_VERSION));
        }
    } else {
        return Err(
            VMStatus::new(StatusCode::MALFORMED).with_message("Bad binary header".to_string())
        );
    }
    if let Ok(ver) = cursor.read_u8() {
        if ver != minor_ver {
            return Err(VMStatus::new(StatusCode::UNKNOWN_VERSION));
        }
    } else {
        return Err(
            VMStatus::new(StatusCode::MALFORMED).with_message("Bad binary header".to_string())
        );
    }
    cursor.read_u8().map_err(|_| {
        VMStatus::new(StatusCode::MALFORMED).with_message("Bad binary header".to_string())
    })
}
/// Verifies the correctness of the "static" part of the binary's header.
///
/// Returns the offset where the count of tables in the binary.
Verifies the correctness of the "static" part of the binary's header.
Returns the offset where the count of tables in the binary.
Verifies the correctness of the " static " part of the binary ' s header . Returns the offset where the count of tables in the binary .
fn check_binary(cursor: &mut Cursor<&[u8]>) -> BinaryLoaderResult<u8> {
    let mut magic = [0u8; BinaryConstants::LIBRA_MAGIC_SIZE];
    if let Ok(count) = cursor.read(&mut magic) {
        if count != BinaryConstants::LIBRA_MAGIC_SIZE || magic != BinaryConstants::LIBRA_MAGIC {
            return Err(VMStatus::new(StatusCode::BAD_MAGIC));
        }
    } else {
        return Err(
            VMStatus::new(StatusCode::MALFORMED).with_message("Bad binary header".to_string())
        );
    }
    let major_ver = 1u8;
    let minor_ver = 0u8;
    if let Ok(ver) = cursor.read_u8() {
        if ver != major_ver {
            return Err(VMStatus::new(StatusCode::UNKNOWN_VERSION));
        }
    } else {
        return Err(
            VMStatus::new(StatusCode::MALFORMED).with_message("Bad binary header".to_string())
        );
    }
    if let Ok(ver) = cursor.read_u8() {
        if ver != minor_ver {
            return Err(VMStatus::new(StatusCode::UNKNOWN_VERSION));
        }
    } else {
        return Err(
            VMStatus::new(StatusCode::MALFORMED).with_message("Bad binary header".to_string())
        );
    }
    cursor.read_u8().map_err(|_| {
        VMStatus::new(StatusCode::MALFORMED).with_message("Bad binary header".to_string())
    })
}
fn check_binary ( cursor : & mut Cursor < & [ u8 ] > ) -> BinaryLoaderResult < u8 > { let mut magic = [ 0u8 ; BinaryConstants :: LIBRA_MAGIC_SIZE ] ; if let Ok ( count ) = cursor . read ( & mut magic ) { if count != BinaryConstants :: LIBRA_MAGIC_SIZE || magic != BinaryConstants :: LIBRA_MAGIC { return Err ( VMStatus :: new ( StatusCode :: BAD_MAGIC ) ) ; } } else { return Err ( VMStatus :: new ( StatusCode :: MALFORMED ) . with_message ( " " . to_string ( ) ) ) ; } let major_ver = 1u8 ; let minor_ver = 0u8 ; if let Ok ( ver ) = cursor . read_u8 ( ) { if ver != major_ver { return Err ( VMStatus :: new ( StatusCode :: UNKNOWN_VERSION ) ) ; } } else { return Err ( VMStatus :: new ( StatusCode :: MALFORMED ) . with_message ( " " . to_string ( ) ) ) ; } if let Ok ( ver ) = cursor . read_u8 ( ) { if ver != minor_ver { return Err ( VMStatus :: new ( StatusCode :: UNKNOWN_VERSION ) ) ; } } else { return Err ( VMStatus :: new ( StatusCode :: MALFORMED ) . with_message ( " " . to_string ( ) ) ) ; } cursor . read_u8 ( ) . map_err ( | _ | { VMStatus :: new ( StatusCode :: MALFORMED ) . with_message ( " " . to_string ( ) ) } ) }
Verifies the correctness of the "static" part of the binary's header.
Verifies the correctness of the " static " part of the binary ' s header .
cursor
&mut Cursor<&[u8]>
cursor
&mut Cursor<&[u8]>