### Question:
ShortPacket implements FullPacket { public static HalfParsedPacket<ShortPacket> parse(final ByteBuf bb, final int connIdLength) { final int bbOffset = bb.readerIndex(); final byte firstByte = bb.readByte(); final boolean firstBit = (firstByte & 0x80) == 0x80; if (firstBit) { throw new IllegalArgumentException("First bit must be 0"); } final boolean reserved = (firstByte & 0x40) == 0x40; if (!reserved) { throw new IllegalArgumentException("Reserved bit must be 1"); } final boolean keyPhase = (firstByte & 0x4) == 0x4; final Optional<ConnectionId> connId; if (connIdLength > 0) { connId = Optional.of(ConnectionId.read(connIdLength, bb)); } else { connId = Optional.empty(); } return new HalfParsedPacket<>() { @Override public Optional<Version> getVersion() { return Optional.empty(); } @Override public Optional<ConnectionId> getConnectionId() { return connId; } @Override public ShortPacket complete(final AEADProvider aeadProvider) { final AEAD aead = aeadProvider.get(EncryptionLevel.OneRtt); final int pnOffset = bb.readerIndex(); final int sampleOffset = pnOffset + 4; final byte[] sample = new byte[aead.getSampleLength()]; bb.getBytes(sampleOffset, sample); final byte[] pn = new byte[4]; bb.getBytes(pnOffset, pn); try { final byte[] decryptedHeader = aead.decryptHeader(sample, Bytes.concat(new byte[] {firstByte}, pn), true); final byte decryptedFirstByte = decryptedHeader[0]; final int pnLen = (decryptedFirstByte & 0x3) + 1; final byte[] pnBytes = Arrays.copyOfRange(decryptedHeader, 1, 1 + pnLen); final long packetNumber = PacketNumber.parse(pnBytes); bb.readerIndex(bb.readerIndex() + pnLen); final byte[] aad = new byte[bb.readerIndex() - bbOffset]; bb.getBytes(bbOffset, aad); aad[0] = decryptedFirstByte; for (int i = 0; i < pnBytes.length; i++) { aad[pnOffset - bbOffset + i] = pnBytes[i]; } final Payload payload = Payload.parse(bb, bb.readableBytes(), aead, packetNumber, aad); return new ShortPacket(keyPhase, connId, packetNumber, payload); } catch (final GeneralSecurityException e) { throw new RuntimeException(e); } } }; } ShortPacket(
      final boolean keyPhase,
      final Optional<ConnectionId> connectionId,
      final long packetNumber,
      final Payload payload); static HalfParsedPacket<ShortPacket> parse(final ByteBuf bb, final int connIdLength); static ShortPacket create(
      final boolean keyPhase,
      final Optional<ConnectionId> connectionId,
      final long packetNumber,
      final Frame... frames); @Override PacketType getType(); @Override FullPacket addFrame(final Frame frame); @Override void write(final ByteBuf bb, final AEAD aead); @Override long getPacketNumber(); @Override Optional<ConnectionId> getSourceConnectionId(); @Override Optional<ConnectionId> getDestinationConnectionId(); @Override Payload getPayload(); @Override String toString();  }### Answer:
@Test(expected = IllegalArgumentException.class) public void invalidFirstBit() { final ByteBuf bb = buffer(packet()); bb.setByte(0, Bits.set(bb.getByte(0), 7)); ShortPacket.parse(bb, dest.getLength()); }
@Test(expected = IllegalArgumentException.class) public void invalidSecondBit() { final ByteBuf bb = buffer(packet()); bb.setByte(0, Bits.unset(bb.getByte(0), 6)); ShortPacket.parse(bb, dest.getLength()); }