/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.LicenseException
 *  com.l7tech.gateway.common.audit.AssertionMessages
 *  com.l7tech.gateway.common.audit.AuditDetailMessage
 *  com.l7tech.policy.assertion.AssertionStatus
 *  com.l7tech.policy.assertion.PolicyAssertionException
 *  com.l7tech.policy.assertion.composite.HandleErrorsAssertion
 *  com.l7tech.util.ExceptionUtils
 *  org.springframework.beans.factory.BeanFactory
 *  org.springframework.context.ApplicationContext
 */
package com.l7tech.server.policy.assertion.composite;

import com.l7tech.gateway.common.LicenseException;
import com.l7tech.gateway.common.audit.AssertionMessages;
import com.l7tech.gateway.common.audit.AuditDetailMessage;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.policy.assertion.composite.HandleErrorsAssertion;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.policy.assertion.composite.ServerCompositeAssertion;
import com.l7tech.server.policy.assertion.composite.d;
import com.l7tech.util.ExceptionUtils;
import java.io.IOException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;

public class ServerHandleErrorsAssertion
extends ServerCompositeAssertion<HandleErrorsAssertion> {
    private final ServerCompositeAssertion.AssertionResultListener h = new d(this);
    private static final String[] i;

    public ServerHandleErrorsAssertion(HandleErrorsAssertion handleErrorsAssertion, ApplicationContext applicationContext) throws PolicyAssertionException, LicenseException {
        super(handleErrorsAssertion, (BeanFactory)applicationContext);
    }

    @Override
    public AssertionStatus checkRequest(PolicyEnforcementContext policyEnforcementContext) throws IOException {
        AssertionStatus assertionStatus = AssertionStatus.FAILED;
        try {
            assertionStatus = this.iterateChildren(policyEnforcementContext, this.h);
        }
        catch (PolicyAssertionException policyAssertionException) {
            String[] stringArray = i;
            policyEnforcementContext.setVariable(((HandleErrorsAssertion)this.assertion).getVariablePrefix() + stringArray[1], ExceptionUtils.getMessage((Throwable)policyAssertionException));
            this.logAndAudit((AuditDetailMessage)AssertionMessages.HANDLE_ERRORS_MSG, ExceptionUtils.getMessage((Throwable)policyAssertionException));
            return AssertionStatus.NONE;
        }
        catch (IOException iOException) {
            try {
                if (((HandleErrorsAssertion)this.assertion).isIncludeIOException()) {
                    policyEnforcementContext.setVariable(((HandleErrorsAssertion)this.assertion).getVariablePrefix() + i[0], ExceptionUtils.getMessage((Throwable)iOException));
                    this.logAndAudit((AuditDetailMessage)AssertionMessages.HANDLE_ERRORS_MSG, ExceptionUtils.getMessage((Throwable)iOException));
                    return AssertionStatus.NONE;
                }
            }
            catch (PolicyAssertionException policyAssertionException) {
                throw ServerHandleErrorsAssertion.a(policyAssertionException);
            }
            throw iOException;
        }
        return assertionStatus;
    }

    private static PolicyAssertionException a(PolicyAssertionException policyAssertionException) {
        return policyAssertionException;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[2];
        int n2 = 0;
        String string = "Nn=\u001eO5[\u0005\bNn=\u001eO5[\u0005";
        int n3 = "Nn=\u001eO5[\u0005\bNn=\u001eO5[\u0005".length();
        int n4 = 8;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = ServerHandleErrorsAssertion.c(10, ServerHandleErrorsAssertion.b(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                i = stringArray;
                return;
            }
            n4 = string.charAt(n5);
        }
    }

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String c(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 -> 106;
                    case 1 -> 9;
                    case 2 -> 82;
                    case 3 -> 103;
                    case 4 -> 54;
                    case 5 -> 94;
                    default -> 54;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

