/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.audit.AssertionMessages
 *  com.l7tech.gateway.common.audit.AuditDetailMessage
 *  com.l7tech.policy.assertion.AssertionStatus
 *  com.l7tech.policy.assertion.ExportVariablesAssertion
 *  com.l7tech.policy.assertion.PolicyAssertionException
 *  com.l7tech.policy.variable.NoSuchVariableException
 *  com.l7tech.policy.variable.VariableNotSettableException
 *  com.l7tech.util.ExceptionUtils
 *  org.jetbrains.annotations.NotNull
 */
package com.l7tech.server.policy.assertion;

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.ExportVariablesAssertion;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.policy.variable.NoSuchVariableException;
import com.l7tech.policy.variable.VariableNotSettableException;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.policy.assertion.AbstractServerAssertion;
import com.l7tech.server.policy.variable.ServerVariables;
import com.l7tech.util.ExceptionUtils;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;

public class ServerExportVariablesAssertion
extends AbstractServerAssertion<ExportVariablesAssertion> {
    private static final String[] d;

    public ServerExportVariablesAssertion(@NotNull ExportVariablesAssertion exportVariablesAssertion) {
        if (exportVariablesAssertion == null) {
            ServerExportVariablesAssertion.b(0);
        }
        super(exportVariablesAssertion);
    }

    @Override
    public AssertionStatus checkRequest(PolicyEnforcementContext policyEnforcementContext) throws IOException, PolicyAssertionException {
        PolicyEnforcementContext policyEnforcementContext2 = ServerVariables.getRootContext(policyEnforcementContext);
        String[] stringArray = ((ExportVariablesAssertion)this.assertion).getExportedVars();
        if (stringArray != null) {
            for (String string : stringArray) {
                this.a(string, policyEnforcementContext, policyEnforcementContext2);
            }
        }
        return AssertionStatus.NONE;
    }

    private void a(String string, PolicyEnforcementContext policyEnforcementContext, PolicyEnforcementContext policyEnforcementContext2) {
        Object object;
        try {
            object = policyEnforcementContext.getVariable(string);
        }
        catch (NoSuchVariableException noSuchVariableException) {
            this.getAudit().logAndAudit((AuditDetailMessage)AssertionMessages.NO_SUCH_VARIABLE, new String[]{string});
            return;
        }
        catch (RuntimeException runtimeException) {
            String[] stringArray = new String[1];
            String[] stringArray2 = d;
            stringArray[0] = stringArray2[4] + ExceptionUtils.getMessage((Throwable)runtimeException);
            this.getAudit().logAndAudit((AuditDetailMessage)AssertionMessages.EXCEPTION_WARNING_WITH_MORE_INFO, stringArray, ExceptionUtils.getDebugException((Throwable)runtimeException));
            return;
        }
        try {
            String[] stringArray = d;
            policyEnforcementContext2.setVariable(stringArray[3] + string, object);
        }
        catch (VariableNotSettableException variableNotSettableException) {
            this.getAudit().logAndAudit((AuditDetailMessage)AssertionMessages.VARIABLE_NOTSET, new String[]{string});
        }
        catch (RuntimeException runtimeException) {
            this.getAudit().logAndAudit((AuditDetailMessage)AssertionMessages.EXCEPTION_WARNING_WITH_MORE_INFO, new String[]{d[5] + ExceptionUtils.getMessage((Throwable)runtimeException)}, ExceptionUtils.getDebugException((Throwable)runtimeException));
        }
    }

    private static /* synthetic */ void b(int n2) {
        String[] stringArray = d;
        throw new IllegalArgumentException(String.format(stringArray[6], stringArray[2], stringArray[1], stringArray[0]));
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[7];
                var3_1 = 0;
                var2_2 = "`IGZi$A?OD\u001cq-M9CA\u001cn\u007fK*E[\u001cmuU5CP\u001c|iJ9R]Zrt\u0016\u000fE[Exh|$PFAiLX.IHQq\u007fJ\u001dSZVonP3N\t=SZVonP3N\u001ay\u0005z{\\H|\u0018\u0005\f\u001do\u007fH)EZG3iQ=RLW3\u0019\tNHQq\u007f\u0019(O\tAx{]|VHAt{[0E\u0013\u0013";
                var4_3 = "`IGZi$A?OD\u001cq-M9CA\u001cn\u007fK*E[\u001cmuU5CP\u001c|iJ9R]Zrt\u0016\u000fE[Exh|$PFAiLX.IHQq\u007fJ\u001dSZVonP3N\t=SZVonP3N\u001ay\u0005z{\\H|\u0018\u0005\f\u001do\u007fH)EZG3iQ=RLW3\u0019\tNHQq\u007f\u0019(O\tAx{]|VHAt{[0E\u0013\u0013".length();
                var1_4 = 6;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 43;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = ServerExportVariablesAssertion.b(v0, ServerExportVariablesAssertion.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "L\u000b\r\u00144:\\m\nL\u0005=+\\o\u0004\u001e\u001f9=\u0010|_L>X\u0017\u000b\u00035:\u0012mE\n\u0019*\u007f<W\n\u00188-3\u00109\u0015\r\u000492\u0019m\u0000\u001eV\u007fz\u000f>E\u0003\u0010xz\u000f7@\u001fV5*\u000fmE\u0002\u0019,\u007f\u001e|E\u0002\u000343";
                    var4_3 = "L\u000b\r\u00144:\\m\nL\u0005=+\\o\u0004\u001e\u001f9=\u0010|_L>X\u0017\u000b\u00035:\u0012mE\n\u0019*\u007f<W\n\u00188-3\u00109\u0015\r\u000492\u0019m\u0000\u001eV\u007fz\u000f>E\u0003\u0010xz\u000f7@\u001fV5*\u000fmE\u0002\u0019,\u007f\u001e|E\u0002\u000343".length();
                    var1_4 = 24;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 110;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = ServerExportVariablesAssertion.b(v0, ServerExportVariablesAssertion.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        ServerExportVariablesAssertion.d = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x12);
        }
        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 -> 119;
                    case 1 -> 11;
                    case 2 -> 2;
                    case 3 -> 24;
                    case 4 -> 54;
                    case 5 -> 49;
                    default -> 18;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

