code: private static void validateLength(byte[] data, String dataName,
        int expectedLength) throws IllegalArgumentException {
      if (data.length != expectedLength) {
        throw new IllegalArgumentException(String.format(
            "Invalid %s length. Expected %d bytes but found %d.", dataName,
            expectedLength, data.length));
      }
    }
docs: Checks the length of a byte array.
  
  @param data
  the data to check
  @param dataName
  the name of the field (to include in the exception)
  @param expectedLength
  the length the data should be
  @throws IllegalArgumentException
  if the data is not of the correct length