1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.netty.handler.codec.socksx.v5;
18
19 import io.netty.util.internal.ObjectUtil;
20
21
22
23
24 public class Socks5AuthMethod implements Comparable<Socks5AuthMethod> {
25
26 public static final Socks5AuthMethod NO_AUTH = new Socks5AuthMethod(0x00, "NO_AUTH");
27 public static final Socks5AuthMethod GSSAPI = new Socks5AuthMethod(0x01, "GSSAPI");
28 public static final Socks5AuthMethod PASSWORD = new Socks5AuthMethod(0x02, "PASSWORD");
29
30
31
32
33 public static final Socks5AuthMethod UNACCEPTED = new Socks5AuthMethod(0xff, "UNACCEPTED");
34
35 public static Socks5AuthMethod valueOf(byte b) {
36 switch (b) {
37 case 0x00:
38 return NO_AUTH;
39 case 0x01:
40 return GSSAPI;
41 case 0x02:
42 return PASSWORD;
43 case (byte) 0xFF:
44 return UNACCEPTED;
45 }
46
47 return new Socks5AuthMethod(b);
48 }
49
50 private final byte byteValue;
51 private final String name;
52 private String text;
53
54 public Socks5AuthMethod(int byteValue) {
55 this(byteValue, "UNKNOWN");
56 }
57
58 public Socks5AuthMethod(int byteValue, String name) {
59 this.name = ObjectUtil.checkNotNull(name, "name");
60 this.byteValue = (byte) byteValue;
61 }
62
63 public byte byteValue() {
64 return byteValue;
65 }
66
67 @Override
68 public int hashCode() {
69 return byteValue;
70 }
71
72 @Override
73 public boolean equals(Object obj) {
74 if (!(obj instanceof Socks5AuthMethod)) {
75 return false;
76 }
77
78 return byteValue == ((Socks5AuthMethod) obj).byteValue;
79 }
80
81 @Override
82 public int compareTo(Socks5AuthMethod o) {
83 return byteValue - o.byteValue;
84 }
85
86 @Override
87 public String toString() {
88 String text = this.text;
89 if (text == null) {
90 this.text = text = name + '(' + (byteValue & 0xFF) + ')';
91 }
92 return text;
93 }
94 }