KeyShareExtensionParser extends ExtensionParser<KeyShareExtensionMessage> { @Override public void parseExtensionMessageContent(KeyShareExtensionMessage msg) { LOGGER.debug("Parsing KeyShareExtensionMessage"); parseKeyShareListLength(msg); LOGGER.debug("Parsing KeyShareExtensionMessage"); if (msg.getKeyShareListLength().getValue() + ExtensionByteLength.KEY_SHARE_LIST_LENGTH == msg .getExtensionLength().getValue()) { parseKeyShareListBytes(msg); } else { msg.setKeyShareListLength(msg.getExtensionLength().getValue()); LOGGER.debug("KeyShareListLength: " + msg.getExtensionLength().getValue()); setPointer(getPointer() - ExtensionByteLength.KEY_SHARE_LIST_LENGTH); parseKeyShareListBytes(msg); } int position = 0; entryList = new LinkedList<>(); while (position < msg.getKeyShareListLength().getValue()) { KeyShareEntryParser parser = new KeyShareEntryParser(position, msg.getKeyShareListBytes().getValue()); entryList.add(parser.parse()); if (position == parser.getPointer()) { throw new ParserException("Ran into infinite Loop while parsing KeySharePairs"); } position = parser.getPointer(); } parseKeyShareList(msg); } KeyShareExtensionParser(int startposition, byte[] array, ExtensionType type); @Override void parseExtensionMessageContent(KeyShareExtensionMessage msg);  }
@Test public void testParseExtensionMessageContent() { KeyShareExtensionParser parser = new KeyShareExtensionParser(start, extension, ExtensionType.KEY_SHARE); KeyShareExtensionMessage msg = parser.parse(); assertArrayEquals(msg.getExtensionBytes().getValue(), completeExtension); assertArrayEquals(type.getValue(), msg.getExtensionType().getValue()); assertTrue(extensionLength == msg.getExtensionLength().getValue()); assertArrayEquals(msg.getKeyShareListBytes().getValue(), ksListBytes); assertTrue(ksListLength == msg.getKeyShareListLength().getValue()); }