package io.netty.handler.codec.socks;

import g.a.a.a.a;
import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public final class SocksAuthRequest extends SocksRequest {
    private final String password;
    private final String username;
    private static final CharsetEncoder asciiEncoder = CharsetUtil.encoder(CharsetUtil.US_ASCII);
    private static final SocksSubnegotiationVersion SUBNEGOTIATION_VERSION = SocksSubnegotiationVersion.AUTH_PASSWORD;

    public SocksAuthRequest(String str, String str2) {
        super(SocksRequestType.AUTH);
        Objects.requireNonNull(str, "username");
        Objects.requireNonNull(str2, "username");
        CharsetEncoder charsetEncoder = asciiEncoder;
        if (!charsetEncoder.canEncode(str) || !charsetEncoder.canEncode(str2)) {
            throw new IllegalArgumentException(a.u("username: ", str, " or password: **** values should be in pure ascii"));
        }
        if (str.length() > 255) {
            throw new IllegalArgumentException(a.u("username: ", str, " exceeds 255 char limit"));
        }
        if (str2.length() > 255) {
            throw new IllegalArgumentException("password: **** exceeds 255 char limit");
        }
        this.username = str;
        this.password = str2;
    }

    @Override // io.netty.handler.codec.socks.SocksMessage
    public void encodeAsByteBuf(ByteBuf byteBuf) {
        byteBuf.writeByte(SUBNEGOTIATION_VERSION.byteValue());
        byteBuf.writeByte(this.username.length());
        String str = this.username;
        Charset charset = CharsetUtil.US_ASCII;
        byteBuf.writeCharSequence(str, charset);
        byteBuf.writeByte(this.password.length());
        byteBuf.writeCharSequence(this.password, charset);
    }

    public String password() {
        return this.password;
    }

    public String username() {
        return this.username;
    }
}
