/** * Checks if the message has an ExtensionsLength field * * @return True if the message has an ExtensionLength field */ protected boolean hasExtensionLengthField() { return msg.getExtensionsLength() != null; }
/** * Checks if the ExtensionsLengthField has a value greater than Zero, eg. if * there are Extensions present. * * @param message * Message to check * @return True if the message has Extensions */ protected boolean hasExtensions(T message) { return message.getExtensionsLength().getValue() > 0; }
/** * Writes the ExtensionLength field of the message into the final byte[] */ protected void writeExtensionLength() { appendInt(msg.getExtensionsLength().getValue(), HandshakeByteLength.EXTENSION_LENGTH); LOGGER.debug("ExtensionLength: " + msg.getExtensionsLength().getValue()); }
/** * Reads the next bytes as the ExtensionLength and writes them in the * message * * @param message * Message to write in */ protected void parseExtensionLength(T message) { message.setExtensionsLength(parseIntField(HandshakeByteLength.EXTENSION_LENGTH)); LOGGER.debug("ExtensionLength:" + message.getExtensionsLength().getValue()); }
protected void prepareExtensionLength() { msg.setExtensionsLength(msg.getExtensionBytes().getValue().length); LOGGER.debug("ExtensionLength: " + msg.getExtensionsLength().getValue()); }
/** * Reads the next bytes as the ExtensionBytes and writes them in the message * and adds parsed Extensions to the message * * @param message * Message to write in */ protected void parseExtensionBytes(T message) { byte[] extensionBytes = parseByteArrayField(message.getExtensionsLength().getValue()); message.setExtensionBytes(extensionBytes); LOGGER.debug("ExtensionBytes:" + ArrayConverter.bytesToHexString(extensionBytes, false)); List<ExtensionMessage> extensionMessages = new LinkedList<>(); int pointer = 0; while (pointer < extensionBytes.length) { ExtensionParser parser = ExtensionParserFactory.getExtensionParser(extensionBytes, pointer, message.getHandshakeMessageType()); extensionMessages.add(parser.parse()); if (pointer == parser.getPointer()) { throw new ParserException("Ran into infinite Loop while parsing Extensions"); } pointer = parser.getPointer(); } message.setExtensions(extensionMessages); }