View Javadoc
1   /*
2    * Copyright 2013 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  
17  package io.netty.handler.codec.socksx;
18  
19  /**
20   * The version of SOCKS protocol.
21   */
22  public enum SocksVersion {
23      /**
24       * SOCKS protocol version 4a (or 4)
25       */
26      SOCKS4a((byte) 0x04),
27      /**
28       * SOCKS protocol version 5
29       */
30      SOCKS5((byte) 0x05),
31      /**
32       * Unknown protocol version
33       */
34      UNKNOWN((byte) 0xff);
35  
36      /**
37       * Returns the {@link SocksVersion} that corresponds to the specified version field value,
38       * as defined in the protocol specification.
39       *
40       * @return {@link #UNKNOWN} if the specified value does not represent a known SOCKS protocol version
41       */
42      public static SocksVersion valueOf(byte b) {
43          if (b == SOCKS4a.byteValue()) {
44              return SOCKS4a;
45          }
46          if (b == SOCKS5.byteValue()) {
47              return SOCKS5;
48          }
49          return UNKNOWN;
50      }
51  
52      private final byte b;
53  
54      SocksVersion(byte b) {
55          this.b = b;
56      }
57  
58      /**
59       * Returns the value of the version field, as defined in the protocol specification.
60       */
61      public byte byteValue() {
62          return b;
63      }
64  }