@Test public void testParseBasic() throws Exception { Assert.assertThat(impl.parse("TLSv1"), CoreMatchers.equalTo(TLS.V_1_0.version)); Assert.assertThat(impl.parse("TLSv1.1"), CoreMatchers.equalTo(TLS.V_1_1.version)); Assert.assertThat(impl.parse("TLSv1.2"), CoreMatchers.equalTo(TLS.V_1_2.version)); Assert.assertThat(impl.parse("TLSv1.3"), CoreMatchers.equalTo(TLS.V_1_3.version)); Assert.assertThat(impl.parse("TLSv22.356"), CoreMatchers.equalTo(new ProtocolVersion("TLS", 22, 356))); }
ProtocolVersion parse( final CharSequence buffer, final Tokenizer.Cursor cursor, final BitSet delimiters) throws ParseException { final int lowerBound = cursor.getLowerBound(); final int upperBound = cursor.getUpperBound(); int pos = cursor.getPos(); if (pos + 4 > cursor.getUpperBound()) { throw new ParseException("Invalid TLS protocol version", buffer, lowerBound, upperBound, pos); } if (buffer.charAt(pos) != 'T' || buffer.charAt(pos + 1) != 'L' || buffer.charAt(pos + 2) != 'S' || buffer.charAt(pos + 3) != 'v') { throw new ParseException("Invalid TLS protocol version", buffer, lowerBound, upperBound, pos); } pos = pos + 4; cursor.updatePos(pos); if (cursor.atEnd()) { throw new ParseException("Invalid TLS version", buffer, lowerBound, upperBound, pos); } final String s = this.tokenizer.parseToken(buffer, cursor, delimiters); final int idx = s.indexOf('.'); if (idx == -1) { final int major; try { major = Integer.parseInt(s); } catch (final NumberFormatException e) { throw new ParseException("Invalid TLS major version", buffer, lowerBound, upperBound, pos); } return new ProtocolVersion("TLS", major, 0); } else { final String s1 = s.substring(0, idx); final int major; try { major = Integer.parseInt(s1); } catch (final NumberFormatException e) { throw new ParseException("Invalid TLS major version", buffer, lowerBound, upperBound, pos); } final String s2 = s.substring(idx + 1); final int minor; try { minor = Integer.parseInt(s2); } catch (final NumberFormatException e) { throw new ParseException("Invalid TLS minor version", buffer, lowerBound, upperBound, pos); } return new ProtocolVersion("TLS", major, minor); } }
TlsVersionParser { ProtocolVersion parse( final CharSequence buffer, final Tokenizer.Cursor cursor, final BitSet delimiters) throws ParseException { final int lowerBound = cursor.getLowerBound(); final int upperBound = cursor.getUpperBound(); int pos = cursor.getPos(); if (pos + 4 > cursor.getUpperBound()) { throw new ParseException("Invalid TLS protocol version", buffer, lowerBound, upperBound, pos); } if (buffer.charAt(pos) != 'T' || buffer.charAt(pos + 1) != 'L' || buffer.charAt(pos + 2) != 'S' || buffer.charAt(pos + 3) != 'v') { throw new ParseException("Invalid TLS protocol version", buffer, lowerBound, upperBound, pos); } pos = pos + 4; cursor.updatePos(pos); if (cursor.atEnd()) { throw new ParseException("Invalid TLS version", buffer, lowerBound, upperBound, pos); } final String s = this.tokenizer.parseToken(buffer, cursor, delimiters); final int idx = s.indexOf('.'); if (idx == -1) { final int major; try { major = Integer.parseInt(s); } catch (final NumberFormatException e) { throw new ParseException("Invalid TLS major version", buffer, lowerBound, upperBound, pos); } return new ProtocolVersion("TLS", major, 0); } else { final String s1 = s.substring(0, idx); final int major; try { major = Integer.parseInt(s1); } catch (final NumberFormatException e) { throw new ParseException("Invalid TLS major version", buffer, lowerBound, upperBound, pos); } final String s2 = s.substring(idx + 1); final int minor; try { minor = Integer.parseInt(s2); } catch (final NumberFormatException e) { throw new ParseException("Invalid TLS minor version", buffer, lowerBound, upperBound, pos); } return new ProtocolVersion("TLS", major, minor); } } }
TlsVersionParser { ProtocolVersion parse( final CharSequence buffer, final Tokenizer.Cursor cursor, final BitSet delimiters) throws ParseException { final int lowerBound = cursor.getLowerBound(); final int upperBound = cursor.getUpperBound(); int pos = cursor.getPos(); if (pos + 4 > cursor.getUpperBound()) { throw new ParseException("Invalid TLS protocol version", buffer, lowerBound, upperBound, pos); } if (buffer.charAt(pos) != 'T' || buffer.charAt(pos + 1) != 'L' || buffer.charAt(pos + 2) != 'S' || buffer.charAt(pos + 3) != 'v') { throw new ParseException("Invalid TLS protocol version", buffer, lowerBound, upperBound, pos); } pos = pos + 4; cursor.updatePos(pos); if (cursor.atEnd()) { throw new ParseException("Invalid TLS version", buffer, lowerBound, upperBound, pos); } final String s = this.tokenizer.parseToken(buffer, cursor, delimiters); final int idx = s.indexOf('.'); if (idx == -1) { final int major; try { major = Integer.parseInt(s); } catch (final NumberFormatException e) { throw new ParseException("Invalid TLS major version", buffer, lowerBound, upperBound, pos); } return new ProtocolVersion("TLS", major, 0); } else { final String s1 = s.substring(0, idx); final int major; try { major = Integer.parseInt(s1); } catch (final NumberFormatException e) { throw new ParseException("Invalid TLS major version", buffer, lowerBound, upperBound, pos); } final String s2 = s.substring(idx + 1); final int minor; try { minor = Integer.parseInt(s2); } catch (final NumberFormatException e) { throw new ParseException("Invalid TLS minor version", buffer, lowerBound, upperBound, pos); } return new ProtocolVersion("TLS", major, minor); } } TlsVersionParser(); }
TlsVersionParser { ProtocolVersion parse( final CharSequence buffer, final Tokenizer.Cursor cursor, final BitSet delimiters) throws ParseException { final int lowerBound = cursor.getLowerBound(); final int upperBound = cursor.getUpperBound(); int pos = cursor.getPos(); if (pos + 4 > cursor.getUpperBound()) { throw new ParseException("Invalid TLS protocol version", buffer, lowerBound, upperBound, pos); } if (buffer.charAt(pos) != 'T' || buffer.charAt(pos + 1) != 'L' || buffer.charAt(pos + 2) != 'S' || buffer.charAt(pos + 3) != 'v') { throw new ParseException("Invalid TLS protocol version", buffer, lowerBound, upperBound, pos); } pos = pos + 4; cursor.updatePos(pos); if (cursor.atEnd()) { throw new ParseException("Invalid TLS version", buffer, lowerBound, upperBound, pos); } final String s = this.tokenizer.parseToken(buffer, cursor, delimiters); final int idx = s.indexOf('.'); if (idx == -1) { final int major; try { major = Integer.parseInt(s); } catch (final NumberFormatException e) { throw new ParseException("Invalid TLS major version", buffer, lowerBound, upperBound, pos); } return new ProtocolVersion("TLS", major, 0); } else { final String s1 = s.substring(0, idx); final int major; try { major = Integer.parseInt(s1); } catch (final NumberFormatException e) { throw new ParseException("Invalid TLS major version", buffer, lowerBound, upperBound, pos); } final String s2 = s.substring(idx + 1); final int minor; try { minor = Integer.parseInt(s2); } catch (final NumberFormatException e) { throw new ParseException("Invalid TLS minor version", buffer, lowerBound, upperBound, pos); } return new ProtocolVersion("TLS", major, minor); } } TlsVersionParser();  }
TlsVersionParser { ProtocolVersion parse( final CharSequence buffer, final Tokenizer.Cursor cursor, final BitSet delimiters) throws ParseException { final int lowerBound = cursor.getLowerBound(); final int upperBound = cursor.getUpperBound(); int pos = cursor.getPos(); if (pos + 4 > cursor.getUpperBound()) { throw new ParseException("Invalid TLS protocol version", buffer, lowerBound, upperBound, pos); } if (buffer.charAt(pos) != 'T' || buffer.charAt(pos + 1) != 'L' || buffer.charAt(pos + 2) != 'S' || buffer.charAt(pos + 3) != 'v') { throw new ParseException("Invalid TLS protocol version", buffer, lowerBound, upperBound, pos); } pos = pos + 4; cursor.updatePos(pos); if (cursor.atEnd()) { throw new ParseException("Invalid TLS version", buffer, lowerBound, upperBound, pos); } final String s = this.tokenizer.parseToken(buffer, cursor, delimiters); final int idx = s.indexOf('.'); if (idx == -1) { final int major; try { major = Integer.parseInt(s); } catch (final NumberFormatException e) { throw new ParseException("Invalid TLS major version", buffer, lowerBound, upperBound, pos); } return new ProtocolVersion("TLS", major, 0); } else { final String s1 = s.substring(0, idx); final int major; try { major = Integer.parseInt(s1); } catch (final NumberFormatException e) { throw new ParseException("Invalid TLS major version", buffer, lowerBound, upperBound, pos); } final String s2 = s.substring(idx + 1); final int minor; try { minor = Integer.parseInt(s2); } catch (final NumberFormatException e) { throw new ParseException("Invalid TLS minor version", buffer, lowerBound, upperBound, pos); } return new ProtocolVersion("TLS", major, minor); } } TlsVersionParser();  final static TlsVersionParser INSTANCE; }