/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.policy.assertion.AssertionStatus
 *  com.l7tech.policy.assertion.xmlsec.LookupTrustedCertificateAssertion
 *  com.l7tech.security.cert.TrustedCert
 *  com.l7tech.security.xml.SecurityTokenResolver
 *  com.l7tech.util.ExceptionUtils
 *  com.l7tech.util.Functions$Unary
 *  com.l7tech.util.Option
 *  jakarta.inject.Inject
 *  jakarta.inject.Named
 */
package com.l7tech.server.policy.assertion.xmlsec;

import com.l7tech.objectmodel.FindException;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.xmlsec.LookupTrustedCertificateAssertion;
import com.l7tech.security.cert.TrustedCert;
import com.l7tech.security.xml.SecurityTokenResolver;
import com.l7tech.server.identity.cert.TrustedCertCache;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.policy.assertion.AbstractServerAssertion;
import com.l7tech.server.policy.assertion.xmlsec.t;
import com.l7tech.util.ExceptionUtils;
import com.l7tech.util.Functions;
import com.l7tech.util.Option;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import java.math.BigInteger;
import java.security.cert.X509Certificate;
import java.util.Collection;
import javax.security.auth.x500.X500Principal;

public class ServerLookupTrustedCertificateAssertion
extends AbstractServerAssertion<LookupTrustedCertificateAssertion> {
    @Inject
    private TrustedCertCache trustedCertCache;
    @Inject
    @Named(value="securityTokenResolver")
    private SecurityTokenResolver securityTokenResolver;
    private final String[] d;
    private static final Functions.Unary<X509Certificate, TrustedCert> e;
    private static final String[] f;

    public ServerLookupTrustedCertificateAssertion(LookupTrustedCertificateAssertion lookupTrustedCertificateAssertion) {
        super(lookupTrustedCertificateAssertion);
        this.d = lookupTrustedCertificateAssertion.getVariablesUsed();
    }

    /*
     * Exception decompiling
     */
    @Override
    public AssertionStatus checkRequest(PolicyEnforcementContext var1_1) {
        /*
         * This method has failed to decompile.  When submitting a bug report, please provide this stack trace, and (if you hold appropriate legal rights) the relevant class file.
         * 
         * org.benf.cfr.reader.util.ConfusedCFRException: Tried to end blocks [1[TRYBLOCK]], but top level block is 9[SWITCH]
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.processEndingBlocks(Op04StructuredStatement.java:435)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.buildNestedBlocks(Op04StructuredStatement.java:484)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op03SimpleStatement.createInitialStructuredBlock(Op03SimpleStatement.java:736)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisInner(CodeAnalyser.java:850)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisOrWrapFail(CodeAnalyser.java:278)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysis(CodeAnalyser.java:201)
         *     at org.benf.cfr.reader.entities.attributes.AttributeCode.analyse(AttributeCode.java:94)
         *     at org.benf.cfr.reader.entities.Method.analyse(Method.java:531)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseMid(ClassFile.java:1055)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseTop(ClassFile.java:942)
         *     at org.benf.cfr.reader.Driver.doJarVersionTypes(Driver.java:257)
         *     at org.benf.cfr.reader.Driver.doJar(Driver.java:139)
         *     at org.benf.cfr.reader.CfrDriverImpl.analyse(CfrDriverImpl.java:76)
         *     at org.benf.cfr.reader.Main.main(Main.java:54)
         */
        throw new IllegalStateException("Decompilation failed");
    }

    private X500Principal a(String string) throws FindException {
        try {
            return new X500Principal(string);
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw new FindException(f[1] + ExceptionUtils.getMessage((Throwable)illegalArgumentException), (Throwable)illegalArgumentException);
        }
    }

    private BigInteger b(String string) throws FindException {
        try {
            return new BigInteger(string);
        }
        catch (NumberFormatException numberFormatException) {
            throw new FindException(f[0] + ExceptionUtils.getMessage((Throwable)numberFormatException), (Throwable)numberFormatException);
        }
    }

    private void a(PolicyEnforcementContext policyEnforcementContext, Collection<X509Certificate> collection, boolean bl2) {
        String string = ((LookupTrustedCertificateAssertion)this.assertion).getVariableName();
        X509Certificate[] x509CertificateArray = bl2 ? collection.toArray(new X509Certificate[collection.size()]) : Option.first(collection).toNull();
        policyEnforcementContext.setVariable(string, x509CertificateArray);
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[2];
        int n2 = 0;
        String string = "\u001femFVZevh~UNZg?hzS_\u0013r3yrFV\u0013o#fyBH\t!\f\u001femFVZevOU\u001d\u001a";
        int n3 = "\u001femFVZevh~UNZg?hzS_\u0013r3yrFV\u0013o#fyBH\t!\f\u001femFVZevOU\u001d\u001a".length();
        int n4 = 35;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = ServerLookupTrustedCertificateAssertion.b(87, ServerLookupTrustedCertificateAssertion.c(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                f = stringArray;
                e = new t();
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static FindException a(FindException findException) {
        return findException;
    }

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String b(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 -> 1;
                    case 1 -> 92;
                    case 2 -> 76;
                    case 3 -> 112;
                    case 4 -> 109;
                    case 5 -> 100;
                    default -> 86;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

