/*
 * 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.gateway.common.audit.AuditFactory
 *  com.l7tech.message.Message
 *  com.l7tech.policy.assertion.Assertion
 *  com.l7tech.policy.assertion.AssertionStatus
 *  com.l7tech.policy.assertion.MessageTargetable
 *  com.l7tech.policy.assertion.PolicyAssertionException
 *  com.l7tech.policy.variable.NoSuchVariableException
 *  com.l7tech.util.ExceptionUtils
 *  org.jetbrains.annotations.NotNull
 *  org.jetbrains.annotations.Nullable
 */
package com.l7tech.server.policy.assertion;

import com.l7tech.gateway.common.audit.AssertionMessages;
import com.l7tech.gateway.common.audit.AuditDetailMessage;
import com.l7tech.gateway.common.audit.AuditFactory;
import com.l7tech.message.Message;
import com.l7tech.policy.assertion.Assertion;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.MessageTargetable;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.policy.variable.NoSuchVariableException;
import com.l7tech.server.message.AuthenticationContext;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.policy.assertion.AbstractServerAssertion;
import com.l7tech.util.ExceptionUtils;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public abstract class AbstractMessageTargetableServerAssertion<AT extends Assertion>
extends AbstractServerAssertion<AT> {
    private static final String[] r;

    public AbstractMessageTargetableServerAssertion(@NotNull AT AT) {
        if (AT == null) {
            AbstractMessageTargetableServerAssertion.b(0);
        }
        super(AT);
    }

    public AbstractMessageTargetableServerAssertion(@NotNull AT AT, @Nullable AuditFactory auditFactory) {
        if (AT == null) {
            AbstractMessageTargetableServerAssertion.b(1);
        }
        super(AT, auditFactory);
    }

    @Override
    public AssertionStatus checkRequest(PolicyEnforcementContext policyEnforcementContext) throws IOException, PolicyAssertionException {
        Message message;
        String string = ((MessageTargetable)this.assertion).getTargetName();
        try {
            message = policyEnforcementContext.getTargetMessage((MessageTargetable)this.assertion);
        }
        catch (NoSuchVariableException noSuchVariableException) {
            this.logAndAudit((AuditDetailMessage)AssertionMessages.MESSAGE_TARGET_ERROR, noSuchVariableException.getVariable(), ExceptionUtils.getMessage((Throwable)noSuchVariableException));
            return AssertionStatus.FAILED;
        }
        return this.doCheckRequest(policyEnforcementContext, message, string, policyEnforcementContext.getAuthenticationContext(message));
    }

    protected AssertionStatus doCheckRequest(PolicyEnforcementContext policyEnforcementContext, Message message, String string, AuthenticationContext authenticationContext) throws IOException, PolicyAssertionException {
        return AssertionStatus.FAILED;
    }

    protected boolean isRequest() {
        return Assertion.isRequest((Assertion)this.assertion);
    }

    protected boolean isResponse() {
        return Assertion.isResponse((Assertion)this.assertion);
    }

    protected AssertionStatus getBadMessageStatus() {
        AssertionStatus assertionStatus = AssertionStatus.FALSIFIED;
        if (this.isRequest()) {
            assertionStatus = AssertionStatus.BAD_REQUEST;
        } else if (this.isResponse()) {
            assertionStatus = AssertionStatus.BAD_RESPONSE;
        }
        return assertionStatus;
    }

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

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[4];
                var3_1 = 0;
                var2_2 = "@0;\u000b|q\t\u001d*&\u0007z;|\u00137";
                var4_3 = "@0;\u000b|q\t\u001d*&\u0007z;|\u00137".length();
                var1_4 = 6;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = AbstractMessageTargetableServerAssertion.b(v0, AbstractMessageTargetableServerAssertion.f(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u007fVX-\u0004\u0018\u0001yZ]-\u001bJ\u0007j\\G-\u0018@\u0019uZL-\t\\\u0006yKAk\u0007AZ][Fv\u001aN\u0016htPq\u001bN\u0012ymTp\u000fJ\u0001}[Yg;J\u0007j\\GC\u001b\\\u0010nM\\m\u0006>]KRw\u0005J\u001bh\u0019Sm\u001a\u000f5RVAL\u001dC\u0019<ITp\tB\u0010h\\G\"O\n\u0006;\u0019ZdH\n\u00062\u001cF\"\u0005Z\u0006h\u0019[m\u001c\u000f\u0017y\u0019[w\u0004C";
                    var4_3 = "\u007fVX-\u0004\u0018\u0001yZ]-\u001bJ\u0007j\\G-\u0018@\u0019uZL-\t\\\u0006yKAk\u0007AZ][Fv\u001aN\u0016htPq\u001bN\u0012ymTp\u000fJ\u0001}[Yg;J\u0007j\\GC\u001b\\\u0010nM\\m\u0006>]KRw\u0005J\u001bh\u0019Sm\u001a\u000f5RVAL\u001dC\u0019<ITp\tB\u0010h\\G\"O\n\u0006;\u0019ZdH\n\u00062\u001cF\"\u0005Z\u0006h\u0019[m\u001c\u000f\u0017y\u0019[w\u0004C".length();
                    var1_4 = 75;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 81;
                        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++] = AbstractMessageTargetableServerAssertion.b(v0, AbstractMessageTargetableServerAssertion.f(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;
            }
        }
        AbstractMessageTargetableServerAssertion.r = var5;
    }

    private static char[] f(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x24);
        }
        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 -> 77;
                    case 1 -> 104;
                    case 2 -> 100;
                    case 3 -> 83;
                    case 4 -> 57;
                    case 5 -> 126;
                    default -> 36;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

