pub fn parse_nts_packet<T: Aead>(
    buff: &[u8],
    decryptor: &mut T,
) -> Result<NtsPacket, std::io::Error> {
    let header = parse_packet_header(buff)?;
    let mut reader = Cursor::new(buff);
    let mut auth_exts = Vec::new();
    reader.set_position(HEADER_SIZE);
    while buff.len() - reader.position() as usize >= 4 {
        let ext_type = reader.read_u16::<BigEndian>()?;
        let ext_len = (reader.read_u16::<BigEndian>()? - 4) as usize; // RFC 7822
        match type_from_wire(ext_type) {
            NTSAuthenticator => {
                let mut auth_ext_contents = vec![0; ext_len];
                reader.read(&mut auth_ext_contents)?;
                let oldpos = (reader.position() - 4 - (ext_len as u64)) as usize;
                let enc_ext_data =
                    parse_decrypt_auth_ext::<T>(&buff[0..oldpos], &auth_ext_contents, decryptor)?;
                let enc_exts = parse_extensions(&enc_ext_data)?;
                return Ok(NtsPacket {
                    header: header,
                    auth_exts: auth_exts,
                    auth_enc_exts: enc_exts,
                });
            }
            _ => {
                let mut contents: Vec<u8> = vec![0; ext_len];
                reader.read(&mut contents)?;
                auth_exts.push(NtpExtension {
                    ext_type: type_from_wire(ext_type),
                    contents: contents,
                });
            }
        }
    }
    return Err(Error::new(
        ErrorKind::InvalidInput,
        "never saw the authenticator",
    ));
}
/// parse_nts_packet parses an NTS packet.
parse_nts_packet parses an NTS packet.
parse_nts_packet parses an NTS packet .
pub fn parse_nts_packet<T: Aead>(
    buff: &[u8],
    decryptor: &mut T,
) -> Result<NtsPacket, std::io::Error> {
    let header = parse_packet_header(buff)?;
    let mut reader = Cursor::new(buff);
    let mut auth_exts = Vec::new();
    reader.set_position(HEADER_SIZE);
    while buff.len() - reader.position() as usize >= 4 {
        let ext_type = reader.read_u16::<BigEndian>()?;
        let ext_len = (reader.read_u16::<BigEndian>()? - 4) as usize; // RFC 7822
        match type_from_wire(ext_type) {
            NTSAuthenticator => {
                let mut auth_ext_contents = vec![0; ext_len];
                reader.read(&mut auth_ext_contents)?;
                let oldpos = (reader.position() - 4 - (ext_len as u64)) as usize;
                let enc_ext_data =
                    parse_decrypt_auth_ext::<T>(&buff[0..oldpos], &auth_ext_contents, decryptor)?;
                let enc_exts = parse_extensions(&enc_ext_data)?;
                return Ok(NtsPacket {
                    header: header,
                    auth_exts: auth_exts,
                    auth_enc_exts: enc_exts,
                });
            }
            _ => {
                let mut contents: Vec<u8> = vec![0; ext_len];
                reader.read(&mut contents)?;
                auth_exts.push(NtpExtension {
                    ext_type: type_from_wire(ext_type),
                    contents: contents,
                });
            }
        }
    }
    return Err(Error::new(
        ErrorKind::InvalidInput,
        "never saw the authenticator",
    ));
}
pub fn parse_nts_packet < T : Aead > ( buff : & [ u8 ] , decryptor : & mut T , ) -> Result < NtsPacket , std :: io :: Error > { let header = parse_packet_header ( buff ) ? ; let mut reader = Cursor :: new ( buff ) ; let mut auth_exts = Vec :: new ( ) ; reader . set_position ( HEADER_SIZE ) ; while buff . len ( ) - reader . position ( ) as usize >= 4 { let ext_type = reader . read_u16 :: < BigEndian > ( ) ? ; let ext_len = ( reader . read_u16 :: < BigEndian > ( ) ? - 4 ) as usize ; // RFC 7822 match type_from_wire ( ext_type ) { NTSAuthenticator => { let mut auth_ext_contents = vec ! [ 0 ext_len ] ; reader . read ( & mut auth_ext_contents ) ? ; let oldpos = ( reader . position ( ) - 4 - ( ext_len as u64 ) ) as usize ; let enc_ext_data = parse_decrypt_auth_ext :: < T > ( & buff [ 0 .. oldpos ] , & auth_ext_contents , decryptor ) ? ; let enc_exts = parse_extensions ( & enc_ext_data ) ? ; return Ok ( NtsPacket { header : header , auth_exts : auth_exts , auth_enc_exts : enc_exts , } ) ; } _ => { let mut contents : Vec < u8 > = vec ! [ 0 ext_len ] ; reader . read ( & mut contents ) ? ; auth_exts . push ( NtpExtension { ext_type : type_from_wire ( ext_type ) , contents : contents , } ) ; } } } return Err ( Error :: new ( ErrorKind :: InvalidInput , " " , ) ) ; }
parse_nts_packet parses an NTS packet.
parse_nts_packet parses an NTS packet .
buff
&[u8]
decryptor
&mut T
buff
&[u8]
decryptor
&mut T