/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.io.CertUtils
 *  com.l7tech.common.mime.ContentTypeHeader
 *  com.l7tech.util.ArrayUtils
 *  com.l7tech.util.CausedIOException
 *  com.l7tech.util.Charsets
 *  com.l7tech.util.HexUtils
 */
package com.l7tech.server.security.cert;

import com.l7tech.common.io.CertUtils;
import com.l7tech.common.mime.ContentTypeHeader;
import com.l7tech.server.url.AbstractUrlObjectCache;
import com.l7tech.util.ArrayUtils;
import com.l7tech.util.CausedIOException;
import com.l7tech.util.Charsets;
import com.l7tech.util.HexUtils;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.security.cert.CRLException;
import java.security.cert.X509CRL;

class l
implements AbstractUrlObjectCache.UserObjectFactory<X509CRL> {
    private static final String[] a;

    private l() {
    }

    @Override
    public X509CRL createUserObject(String string, AbstractUrlObjectCache.UserObjectSource userObjectSource) throws IOException {
        byte[] byArray;
        String[] stringArray;
        byte[] byArray2;
        byte[] byArray3;
        Charset charset;
        block16: {
            ContentTypeHeader contentTypeHeader = userObjectSource.getContentType();
            charset = Charsets.UTF8;
            try {
                if (contentTypeHeader == null || !contentTypeHeader.isText()) break block16;
            }
            catch (Throwable throwable) {
                throw l.a(throwable);
            }
            charset = contentTypeHeader.getEncoding();
        }
        if (ArrayUtils.compareArrays((byte[])(byArray3 = userObjectSource.getBytes()), (int)0, (byte[])(byArray2 = (stringArray = a)[1].getBytes(charset)), (int)0, (int)byArray2.length)) {
            try (BufferedReader bufferedReader = new BufferedReader(new StringReader(new String(byArray3, charset)));){
                StringBuilder stringBuilder = new StringBuilder();
                try {
                    if (!bufferedReader.readLine().trim().equals(CertUtils.PEM_CRL_BEGIN_MARKER)) {
                        throw new IllegalArgumentException(stringArray[0]);
                    }
                }
                catch (Throwable throwable) {
                    throw l.a(throwable);
                }
                while (true) {
                    String string2 = bufferedReader.readLine().trim();
                    try {
                        if (string2.equals(CertUtils.PEM_CRL_END_MARKER)) break;
                        stringBuilder.append(string2).append("\n");
                    }
                    catch (Throwable throwable) {
                        throw l.a(throwable);
                    }
                }
                byArray = HexUtils.decodeBase64((String)stringBuilder.toString());
            }
        }
        byArray = byArray3;
        try {
            return (X509CRL)CertUtils.getFactory().generateCRL(new ByteArrayInputStream(byArray));
        }
        catch (CRLException cRLException) {
            throw new CausedIOException(a[2], (Throwable)cRLException);
        }
    }

    private static Throwable a(Throwable throwable) {
        return throwable;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = "pLQ_33 _KF\f#|)EK\u0004Xg\u007f#YN\u0003@.x)\u0016ufa\u0005\u001b\b\u000e\u0001j\u000b\u007fKUM+z(\u0016fq`";
        int n3 = "pLQ_33 _KF\f#|)EK\u0004Xg\u007f#YN\u0003@.x)\u0016ufa\u0005\u001b\b\u000e\u0001j\u000b\u007fKUM+z(\u0016fq`".length();
        int n4 = 32;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = l.a(111, l.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                a = stringArray;
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x23);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 89;
                    case 1 -> 74;
                    case 2 -> 76;
                    case 3 -> 67;
                    case 4 -> 40;
                    case 5 -> 124;
                    default -> 35;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

