1 /*
2 * Copyright 2025 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 package io.netty.handler.codec.socksx.v5;
17
18 import io.netty.handler.codec.DecoderResult;
19 import io.netty.util.internal.ObjectUtil;
20 import io.netty.util.internal.StringUtil;
21
22 /**
23 * The default {@link Socks5PrivateAuthRequest} implementation.
24 * <p>
25 * For custom private authentication protocols, you should implement the {@link Socks5PrivateAuthRequest}
26 * interface directly. Custom protocols should also implement their own encoder/decoder to handle the wire format.
27 * </p>
28 */
29 public final class DefaultSocks5PrivateAuthRequest extends AbstractSocks5Message
30 implements Socks5PrivateAuthRequest {
31
32 /**
33 * The private authentication token.
34 */
35 private final byte[] privateToken;
36
37 /**
38 * Creates a new instance with the specified token.
39 *
40 * @param privateAuthToken the private authentication token
41 */
42 public DefaultSocks5PrivateAuthRequest(final byte[] privateAuthToken) {
43 this.privateToken = ObjectUtil.checkNotNull(privateAuthToken, "privateToken").clone();
44 }
45
46 @Override
47 public byte[] privateToken() {
48 return privateToken.clone();
49 }
50
51 @Override
52 public String toString() {
53 StringBuilder buf = new StringBuilder(StringUtil.simpleClassName(this));
54
55 DecoderResult decoderResult = decoderResult();
56 if (!decoderResult.isSuccess()) {
57 buf.append("(decoderResult: ");
58 buf.append(decoderResult);
59 buf.append(", privateToken: ****)");
60 } else {
61 buf.append("(privateToken: ****)");
62 }
63
64 return buf.toString();
65 }
66 }