fn do_get_packet_offsets(
    packet: &Packet,
    current_offset: u32,
) -> Result<PacketOffsets, PacketError> {
    let message_header_size = serialized_size(&MessageHeader::default()).unwrap() as usize;
    // should have at least 1 signature, sig lengths and the message header
    if (1 + size_of::<Signature>() + message_header_size) > packet.meta.size {
        return Err(PacketError::InvalidLen);
    }

    // read the length of Transaction.signatures (serialized with short_vec)
    let (sig_len_untrusted, sig_size) =
        decode_len(&packet.data).map_err(|_| PacketError::InvalidShortVec)?;

    // Using msg_start_offset which is based on sig_len_untrusted introduces uncertainty.
    // Ultimately, the actual sigverify will determine the uncertainty.
    let msg_start_offset = sig_size + sig_len_untrusted * size_of::<Signature>();

    // Packet should have data at least for signatures, MessageHeader, 1 byte for Message.account_keys.len
    if (msg_start_offset + message_header_size + 1) > packet.meta.size {
        return Err(PacketError::InvalidSignatureLen);
    }

    // read MessageHeader.num_required_signatures (serialized with u8)
    let sig_len_maybe_trusted = packet.data[msg_start_offset] as usize;

    let message_account_keys_len_offset = msg_start_offset + message_header_size;

    // This reads and compares the MessageHeader num_required_signatures and
    // num_readonly_signed_accounts bytes. If num_required_signatures is not larger than
    // num_readonly_signed_accounts, the first account is not debitable, and cannot be charged
    // required transaction fees.
    if packet.data[msg_start_offset] <= packet.data[msg_start_offset + 1] {
        return Err(PacketError::PayerNotWritable);
    }

    // read the length of Message.account_keys (serialized with short_vec)
    let (pubkey_len, pubkey_len_size) = decode_len(&packet.data[message_account_keys_len_offset..])
        .map_err(|_| PacketError::InvalidShortVec)?;

    if (message_account_keys_len_offset + pubkey_len * size_of::<Pubkey>() + pubkey_len_size)
        > packet.meta.size
    {
        return Err(PacketError::InvalidPubkeyLen);
    }

    let sig_start = current_offset as usize + sig_size;
    let msg_start = current_offset as usize + msg_start_offset;
    let pubkey_start = msg_start + message_header_size + pubkey_len_size;

    if sig_len_maybe_trusted != sig_len_untrusted {
        return Err(PacketError::MismatchSignatureLen);
    }

    Ok(PacketOffsets::new(
        sig_len_untrusted as u32,
        sig_start as u32,
        msg_start as u32,
        pubkey_start as u32,
    ))
}
// internal function to be unit-tested; should be used only by get_packet_offsets
internal function to be unit-tested; should be used only by get_packet_offsets
internal function to be unit - tested ; should be used only by get_packet_offsets
fn do_get_packet_offsets(
    packet: &Packet,
    current_offset: u32,
) -> Result<PacketOffsets, PacketError> {
    let message_header_size = serialized_size(&MessageHeader::default()).unwrap() as usize;
    // should have at least 1 signature, sig lengths and the message header
    if (1 + size_of::<Signature>() + message_header_size) > packet.meta.size {
        return Err(PacketError::InvalidLen);
    }
    // read the length of Transaction.signatures (serialized with short_vec)
    let (sig_len_untrusted, sig_size) =
        decode_len(&packet.data).map_err(|_| PacketError::InvalidShortVec)?;
    // Using msg_start_offset which is based on sig_len_untrusted introduces uncertainty.
    // Ultimately, the actual sigverify will determine the uncertainty.
    let msg_start_offset = sig_size + sig_len_untrusted * size_of::<Signature>();
    // Packet should have data at least for signatures, MessageHeader, 1 byte for Message.account_keys.len
    if (msg_start_offset + message_header_size + 1) > packet.meta.size {
        return Err(PacketError::InvalidSignatureLen);
    }
    // read MessageHeader.num_required_signatures (serialized with u8)
    let sig_len_maybe_trusted = packet.data[msg_start_offset] as usize;
    let message_account_keys_len_offset = msg_start_offset + message_header_size;
    // This reads and compares the MessageHeader num_required_signatures and
    // num_readonly_signed_accounts bytes. If num_required_signatures is not larger than
    // num_readonly_signed_accounts, the first account is not debitable, and cannot be charged
    // required transaction fees.
    if packet.data[msg_start_offset] <= packet.data[msg_start_offset + 1] {
        return Err(PacketError::PayerNotWritable);
    }
    // read the length of Message.account_keys (serialized with short_vec)
    let (pubkey_len, pubkey_len_size) = decode_len(&packet.data[message_account_keys_len_offset..])
        .map_err(|_| PacketError::InvalidShortVec)?;
    if (message_account_keys_len_offset + pubkey_len * size_of::<Pubkey>() + pubkey_len_size)
        > packet.meta.size
    {
        return Err(PacketError::InvalidPubkeyLen);
    }
    let sig_start = current_offset as usize + sig_size;
    let msg_start = current_offset as usize + msg_start_offset;
    let pubkey_start = msg_start + message_header_size + pubkey_len_size;
    if sig_len_maybe_trusted != sig_len_untrusted {
        return Err(PacketError::MismatchSignatureLen);
    }
    Ok(PacketOffsets::new(
        sig_len_untrusted as u32,
        sig_start as u32,
        msg_start as u32,
        pubkey_start as u32,
    ))
}
fn do_get_packet_offsets ( packet : & Packet , current_offset : u32 , ) -> Result < PacketOffsets , PacketError > { let message_header_size = serialized_size ( & MessageHeader :: default ( ) ) . unwrap ( ) as usize ; // should have at least 1 signature, sig lengths and the message header if ( 1 + size_of :: < Signature > ( ) + message_header_size ) > packet . meta . size { return Err ( PacketError :: InvalidLen ) ; } // read the length of Transaction.signatures (serialized with short_vec) let ( sig_len_untrusted , sig_size ) = decode_len ( & packet . data ) . map_err ( | _ | PacketError :: InvalidShortVec ) ? ; // Using msg_start_offset which is based on sig_len_untrusted introduces uncertainty. // Ultimately, the actual sigverify will determine the uncertainty. let msg_start_offset = sig_size + sig_len_untrusted * size_of :: < Signature > ( ) ; // Packet should have data at least for signatures, MessageHeader, 1 byte for Message.account_keys.len if ( msg_start_offset + message_header_size + 1 ) > packet . meta . size { return Err ( PacketError :: InvalidSignatureLen ) ; } // read MessageHeader.num_required_signatures (serialized with u8) let sig_len_maybe_trusted = packet . data [ msg_start_offset ] as usize ; let message_account_keys_len_offset = msg_start_offset + message_header_size ; // This reads and compares the MessageHeader num_required_signatures and // num_readonly_signed_accounts bytes. If num_required_signatures is not larger than // num_readonly_signed_accounts, the first account is not debitable, and cannot be charged // required transaction fees. if packet . data [ msg_start_offset ] <= packet . data [ msg_start_offset + 1 ] { return Err ( PacketError :: PayerNotWritable ) ; } // read the length of Message.account_keys (serialized with short_vec) let ( pubkey_len , pubkey_len_size ) = decode_len ( & packet . data [ message_account_keys_len_offset .. ] ) . map_err ( | _ | PacketError :: InvalidShortVec ) ? ; if ( message_account_keys_len_offset + pubkey_len * size_of :: < Pubkey > ( ) + pubkey_len_size ) > packet . meta . size { return Err ( PacketError :: InvalidPubkeyLen ) ; } let sig_start = current_offset as usize + sig_size ; let msg_start = current_offset as usize + msg_start_offset ; let pubkey_start = msg_start + message_header_size + pubkey_len_size ; if sig_len_maybe_trusted != sig_len_untrusted { return Err ( PacketError :: MismatchSignatureLen ) ; } Ok ( PacketOffsets :: new ( sig_len_untrusted as u32 , sig_start as u32 , msg_start as u32 , pubkey_start as u32 , ) ) }
internal function to be unit-tested; should be used only by get_packet_offsets
internal function to be unit - tested ; should be used only by get_packet_offsets
packet
&Packet
current_offset
u32
packet
&Packet
current_offset
u32