fn invalid_initial_payload() {
        let mut buf = [0; 65535];
        let mut pipe = testing::Pipe::default().unwrap();

        let mut b = octets::OctetsMut::with_slice(&mut buf);

        let epoch = packet::Type::Initial.to_epoch().unwrap();

        let pn = 0;
        let pn_len = packet::pkt_num_len(pn).unwrap();

        let hdr = Header {
            ty: packet::Type::Initial,
            version: pipe.client.version,
            dcid: ConnectionId::from_ref(&pipe.client.dcid),
            scid: ConnectionId::from_ref(&pipe.client.scid),
            pkt_num: 0,
            pkt_num_len: pn_len,
            token: pipe.client.token.clone(),
            versions: None,
            key_phase: false,
        };

        hdr.to_bytes(&mut b).unwrap();

        // Payload length is invalid!!!
        let payload_len = 4096;

        let len = pn_len + payload_len;
        b.put_varint(len as u64).unwrap();

        packet::encode_pkt_num(pn, &mut b).unwrap();

        let payload_offset = b.off();

        let frames = [frame::Frame::Padding { len: 10 }];

        for frame in &frames {
            frame.to_bytes(&mut b).unwrap();
        }

        let space = &mut pipe.client.pkt_num_spaces[epoch];

        // Use correct payload length when encrypting the packet.
        let payload_len = frames.iter().fold(0, |acc, x| acc + x.wire_len()) +
            space.crypto_overhead().unwrap();

        let aead = space.crypto_seal.as_ref().unwrap();

        let written = packet::encrypt_pkt(
            &mut b,
            pn,
            pn_len,
            payload_len,
            payload_offset,
            aead,
        )
        .unwrap();

        assert_eq!(pipe.server.timeout(), None);

        assert_eq!(
            pipe.server_recv(&mut buf[..written]),
            Err(Error::InvalidPacket)
        );

        assert!(pipe.server.is_closed());
    }
/// Tests that packets with invalid payload length received before any other
/// valid packet cause the server to close the connection immediately.
Tests that packets with invalid payload length received before any other
valid packet cause the server to close the connection immediately.
Tests that packets with invalid payload length received before any other valid packet cause the server to close the connection immediately .
fn invalid_initial_payload() {
        let mut buf = [0; 65535];
        let mut pipe = testing::Pipe::default().unwrap();
        let mut b = octets::OctetsMut::with_slice(&mut buf);
        let epoch = packet::Type::Initial.to_epoch().unwrap();
        let pn = 0;
        let pn_len = packet::pkt_num_len(pn).unwrap();
        let hdr = Header {
            ty: packet::Type::Initial,
            version: pipe.client.version,
            dcid: ConnectionId::from_ref(&pipe.client.dcid),
            scid: ConnectionId::from_ref(&pipe.client.scid),
            pkt_num: 0,
            pkt_num_len: pn_len,
            token: pipe.client.token.clone(),
            versions: None,
            key_phase: false,
        };
        hdr.to_bytes(&mut b).unwrap();
        // Payload length is invalid!!!
        let payload_len = 4096;
        let len = pn_len + payload_len;
        b.put_varint(len as u64).unwrap();
        packet::encode_pkt_num(pn, &mut b).unwrap();
        let payload_offset = b.off();
        let frames = [frame::Frame::Padding { len: 10 }];
        for frame in &frames {
            frame.to_bytes(&mut b).unwrap();
        }
        let space = &mut pipe.client.pkt_num_spaces[epoch];
        // Use correct payload length when encrypting the packet.
        let payload_len = frames.iter().fold(0, |acc, x| acc + x.wire_len()) +
            space.crypto_overhead().unwrap();
        let aead = space.crypto_seal.as_ref().unwrap();
        let written = packet::encrypt_pkt(
            &mut b,
            pn,
            pn_len,
            payload_len,
            payload_offset,
            aead,
        )
        .unwrap();
        assert_eq!(pipe.server.timeout(), None);
        assert_eq!(
            pipe.server_recv(&mut buf[..written]),
            Err(Error::InvalidPacket)
        );
        assert!(pipe.server.is_closed());
    }
fn invalid_initial_payload ( ) { let mut buf = [ 0 ; 65535 ] ; let mut pipe = testing :: Pipe :: default ( ) . unwrap ( ) ; let mut b = octets :: OctetsMut :: with_slice ( & mut buf ) ; let epoch = packet :: Type :: Initial . to_epoch ( ) . unwrap ( ) ; let pn = 0 ; let pn_len = packet :: pkt_num_len ( pn ) . unwrap ( ) ; let hdr = Header { ty : packet :: Type :: Initial , version : pipe . client . version , dcid : ConnectionId :: from_ref ( & pipe . client . dcid ) , scid : ConnectionId :: from_ref ( & pipe . client . scid ) , pkt_num : 0 , pkt_num_len : pn_len , token : pipe . client . token . clone ( ) , versions : None , key_phase : false , } ; hdr . to_bytes ( & mut b ) . unwrap ( ) ; // Payload length is invalid!!! let payload_len = 4096 ; let len = pn_len + payload_len ; b . put_varint ( len as u64 ) . unwrap ( ) ; packet :: encode_pkt_num ( pn , & mut b ) . unwrap ( ) ; let payload_offset = b . off ( ) ; let frames = [ frame :: Frame :: Padding { len : 10 } ] ; for frame in & frames { frame . to_bytes ( & mut b ) . unwrap ( ) ; } let space = & mut pipe . client . pkt_num_spaces [ epoch ] ; // Use correct payload length when encrypting the packet. let payload_len = frames . iter ( ) . fold ( 0 , | acc , x | acc + x . wire_len ( ) ) + space . crypto_overhead ( ) . unwrap ( ) ; let aead = space . crypto_seal . as_ref ( ) . unwrap ( ) ; let written = packet :: encrypt_pkt ( & mut b , pn , pn_len , payload_len , payload_offset , aead , ) . unwrap ( ) ; assert_eq ! ( pipe server timeout ( ) None ) ; assert_eq ! ( pipe server_recv ( mut buf [ written ] ) Err ( Error InvalidPacket ) ) ; assert ! ( pipe server is_closed ( ) ) ; }
Tests that packets with invalid payload length received before any other
valid packet cause the server to close the connection immediately.
Tests that packets with invalid payload length received before any other valid packet cause the server to close the connection immediately .