public static TokenBindingVersion getExtensionType(byte[] value) { TokenBindingVersion type = MAP.get(ArrayConverter.bytesToInt(value)); return type; }
public static SrtpProtectionProfiles getProfileByType(byte[] value) { return MAP.get(ArrayConverter.bytesToInt(value)); }
public static List<SSL2CipherSuite> getCiphersuites(byte[] values) { List<SSL2CipherSuite> cipherSuites = new LinkedList<>(); int pointer = 0; while (pointer < values.length) { byte[] suiteBytes = Arrays.copyOfRange(values, pointer, pointer + SSL2CipherSuiteLength); int suiteValue = ArrayConverter.bytesToInt(suiteBytes); cipherSuites.add(getCipherSuite(suiteValue)); pointer += SSL2CipherSuiteLength; } return cipherSuites; }
/** * Return the highest protocol version. * * @param list * The List of protocolVersions to search in * @return The highest ProtocolVersion */ public static ProtocolVersion getHighestProtocolVersion(List<ProtocolVersion> list) { ProtocolVersion highestProtocolVersion = null; for (ProtocolVersion pv : list) { if (highestProtocolVersion == null) { highestProtocolVersion = pv; } if (pv != null && ArrayConverter.bytesToInt(pv.getValue()) > ArrayConverter.bytesToInt(highestProtocolVersion .getValue())) { highestProtocolVersion = pv; } } return highestProtocolVersion; }
/** * Parses a number of bytes from the Array and returns them as a byte. * Throws a ParserException if the number of bytes cannot be parsed. Moves * the pointer accordingly. * * @param length * Number of bytes to be parsed * @return An integer representation of the subbyteArray */ protected byte parseByteField(int length) { if (length == 0) { throw new ParserException("Cannot parse byte of size 0"); } if (length > 1) { LOGGER.warn("Parsing byte[] field into a byte of size >1"); } return (byte) ArrayConverter.bytesToInt(parseByteArrayField(length)); }
/** * Parses a number of bytes from the Array and returns them as a int. Throws * a ParserException if the number of bytes cannot be parsed. Moves the * pointer accordingly. * * @param length * Number of bytes to be parsed * @return An integer representation of the subbyteArray */ protected int parseIntField(int length) { if (length == 0) { throw new ParserException("Cannot parse int of size 0"); } return ArrayConverter.bytesToInt(parseByteArrayField(length)); }
/** * Adds a byte[] representation of an int to the final byte[]. If the * Integer is greater than the specified length only the lower length bytes * are serialized. * * @param i * The Integer that should be appended * @param length * The number of bytes which should be reserved for this Integer */ protected final void appendInt(int i, int length) { byte[] bytes = ArrayConverter.intToBytes(i, length); int reconvertedInt = ArrayConverter.bytesToInt(bytes); if (reconvertedInt != i) { LOGGER.warn("Int \"" + i + "\" is too long to write in field of size " + length + ". Only using last " + length + " bytes."); } appendBytes(ArrayConverter.intToBytes(i, length)); }
/** * Writes the SerializedPublicKeyLength of the PSKClientKeyExchangeMessage * into the final byte[] */ private void writePSKIdentityLength(PskDhClientKeyExchangeMessage msg) { appendInt(msg.getIdentityLength().getValue(), HandshakeByteLength.PSK_IDENTITY_LENGTH); LOGGER.debug("SerializedPSKIdentityLength: " + ArrayConverter.bytesToInt(msg.getIdentity().getValue())); }
/** * Writes the SerializedPublicKeyLength of the * PskEcDhClientKeyExchangeMessage into the final byte[] */ private void writePSKIdentityLength(PskEcDhClientKeyExchangeMessage msg) { appendInt(msg.getIdentityLength().getValue(), HandshakeByteLength.PSK_IDENTITY_LENGTH); LOGGER.debug("SerializedPSKIdentityLength: " + ArrayConverter.bytesToInt(msg.getIdentity().getValue())); }