package io.netty.channel.epoll;

import g.a.a.a.a;
import io.netty.util.internal.ObjectUtil;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import kotlinx.serialization.json.internal.AbstractJsonLexerKt;

/* JADX INFO: loaded from: classes.dex */
public final class TcpMd5Util {
    private TcpMd5Util() {
    }

    public static Collection<InetAddress> newTcpMd5Sigs(AbstractEpollChannel abstractEpollChannel, Collection<InetAddress> collection, Map<InetAddress, byte[]> map) {
        ObjectUtil.checkNotNull(abstractEpollChannel, "channel");
        ObjectUtil.checkNotNull(collection, "current");
        ObjectUtil.checkNotNull(map, "newKeys");
        for (Map.Entry<InetAddress, byte[]> entry : map.entrySet()) {
            byte[] value = entry.getValue();
            if (entry.getKey() == null) {
                throw new IllegalArgumentException("newKeys contains an entry with null address: " + map);
            }
            if (value == null) {
                StringBuilder sbF = a.F("newKeys[");
                sbF.append(entry.getKey());
                sbF.append(AbstractJsonLexerKt.END_LIST);
                throw new NullPointerException(sbF.toString());
            }
            if (value.length == 0) {
                StringBuilder sbF2 = a.F("newKeys[");
                sbF2.append(entry.getKey());
                sbF2.append("] has an empty key.");
                throw new IllegalArgumentException(sbF2.toString());
            }
            int length = value.length;
            int i2 = Native.TCP_MD5SIG_MAXKEYLEN;
            if (length > i2) {
                StringBuilder sbF3 = a.F("newKeys[");
                sbF3.append(entry.getKey());
                sbF3.append("] has a key with invalid length; should not exceed the maximum length (");
                sbF3.append(i2);
                sbF3.append(')');
                throw new IllegalArgumentException(sbF3.toString());
            }
        }
        for (InetAddress inetAddress : collection) {
            if (!map.containsKey(inetAddress)) {
                abstractEpollChannel.socket.setTcpMd5Sig(inetAddress, null);
            }
        }
        if (map.isEmpty()) {
            return Collections.emptySet();
        }
        ArrayList arrayList = new ArrayList(map.size());
        for (Map.Entry<InetAddress, byte[]> entry2 : map.entrySet()) {
            abstractEpollChannel.socket.setTcpMd5Sig(entry2.getKey(), entry2.getValue());
            arrayList.add(entry2.getKey());
        }
        return arrayList;
    }
}
