TokenBindingMessageParser extends ProtocolMessageParser<TokenBindingMessage> { @Override protected TokenBindingMessage parseMessageContent() { TokenBindingMessage message = new TokenBindingMessage(); message.setTokenbindingsLength(parseIntField(TokenBindingLength.TOKENBINDINGS)); LOGGER.debug("TokenbindingLength:" + message.getTokenbindingsLength().getValue()); message.setTokenbindingType(parseByteField(TokenBindingLength.BINDING_TYPE)); LOGGER.debug("TokenBindingType:" + message.getTokenbindingType().getValue()); message.setKeyParameter(parseByteField(TokenBindingLength.KEY_PARAMETER)); LOGGER.debug("KeyParameter:" + message.getKeyParameter().getValue()); TokenBindingKeyParameters keyParameter = TokenBindingKeyParameters.getTokenBindingKeyParameter(message .getKeyParameter().getValue()); message.setKeyLength(parseIntField(TokenBindingLength.KEY)); LOGGER.debug("KeyLength:" + message.getKeyLength().getValue()); if (keyParameter.equals(TokenBindingKeyParameters.ECDSAP256)) { message.setPointLength(parseIntField(TokenBindingLength.POINT)); LOGGER.debug("PointLength:" + message.getPointLength().getValue()); message.setPoint(parseByteArrayField(message.getPointLength().getValue())); LOGGER.debug("Point:" + ArrayConverter.bytesToHexString(message.getPoint().getValue())); } else { message.setModulusLength(parseIntField(TokenBindingLength.MODULUS)); message.setModulus(parseByteArrayField(message.getModulusLength().getValue())); message.setPublicExponentLength(parseIntField(TokenBindingLength.PUBLIC_EXPONENT)); message.setPublicExponent(parseByteArrayField(message.getPublicExponentLength().getValue())); } message.setSignatureLength(parseIntField(TokenBindingLength.SIGNATURE)); LOGGER.debug("SignatureLength:" + message.getSignatureLength().getValue()); message.setSignature(parseByteArrayField(message.getSignatureLength().getValue())); LOGGER.debug("Signature:" + ArrayConverter.bytesToHexString(message.getSignature().getValue())); message.setExtensionLength(parseIntField(TokenBindingLength.EXTENSIONS)); LOGGER.debug("ExtensionLength:" + message.getExtensionLength().getValue()); message.setExtensionBytes(parseByteArrayField(message.getExtensionLength().getValue())); LOGGER.debug("Extensions:" + ArrayConverter.bytesToHexString(message.getExtensionBytes().getValue())); return message; } TokenBindingMessageParser(int pointer, byte[] array, ProtocolVersion version, Config config);   }
@Test public void testParseMessageContent() { parser = new TokenBindingMessageParser(0, toParse, version, config); TokenBindingMessage message = parser.parse(); Assert.assertArrayEquals(new byte[0], message.getExtensionBytes().getValue()); assertTrue(message.getExtensionLength().getValue() == 0); assertTrue(message.getSignatureLength().getValue() == 0x40); assertTrue(message.getPointLength().getValue() == 0x40); assertTrue(message.getKeyParameter().getValue() == 0x02); TokenBindingMessageSerializer serializer = new TokenBindingMessageSerializer(message, version); byte[] serialized = serializer.serialize(); Assert.assertArrayEquals(toParse, serialized); }