/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.mime.ContentTypeHeader
 *  com.l7tech.gateway.common.custom.ContentTypeHeaderToCustomConverter
 *  com.l7tech.gateway.common.custom.CustomToMessageTargetableAdaptor
 *  com.l7tech.message.Message
 *  com.l7tech.policy.assertion.MessageTargetable
 *  com.l7tech.policy.assertion.ext.SecurityContext
 *  com.l7tech.policy.assertion.ext.message.CustomContentType
 *  com.l7tech.policy.assertion.ext.message.CustomMessage
 *  com.l7tech.policy.assertion.ext.message.CustomPolicyContext
 *  com.l7tech.policy.assertion.ext.message.format.CustomMessageFormatFactory
 *  com.l7tech.policy.assertion.ext.targetable.CustomMessageTargetable
 *  com.l7tech.policy.assertion.ext.targetable.CustomMessageTargetableSupport
 *  com.l7tech.policy.variable.NoSuchVariableException
 *  com.l7tech.policy.variable.Syntax
 *  com.l7tech.policy.variable.VariableNotSettableException
 *  org.jetbrains.annotations.NotNull
 *  org.jetbrains.annotations.Nullable
 */
package com.l7tech.server.policy.assertion;

import com.l7tech.common.mime.ContentTypeHeader;
import com.l7tech.gateway.common.custom.ContentTypeHeaderToCustomConverter;
import com.l7tech.gateway.common.custom.CustomToMessageTargetableAdaptor;
import com.l7tech.message.Message;
import com.l7tech.policy.assertion.MessageTargetable;
import com.l7tech.policy.assertion.ext.SecurityContext;
import com.l7tech.policy.assertion.ext.message.CustomContentType;
import com.l7tech.policy.assertion.ext.message.CustomMessage;
import com.l7tech.policy.assertion.ext.message.CustomPolicyContext;
import com.l7tech.policy.assertion.ext.message.format.CustomMessageFormatFactory;
import com.l7tech.policy.assertion.ext.targetable.CustomMessageTargetable;
import com.l7tech.policy.assertion.ext.targetable.CustomMessageTargetableSupport;
import com.l7tech.policy.variable.NoSuchVariableException;
import com.l7tech.policy.variable.Syntax;
import com.l7tech.policy.variable.VariableNotSettableException;
import com.l7tech.server.custom.CustomMessageImpl;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.policy.assertion.ServerCustomAssertionHolder;
import com.l7tech.server.policy.assertion.j;
import com.l7tech.server.policy.assertion.k;
import com.l7tech.server.policy.assertion.m;
import com.l7tech.server.policy.assertion.o;
import com.l7tech.server.policy.variable.ExpandVariables;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

class l
extends k
implements CustomPolicyContext {
    private final PolicyEnforcementContext a;
    private final SecurityContext b;
    private final boolean c;
    private final Map d;
    final ServerCustomAssertionHolder this$0;
    private static final String[] e;

    public l(@NotNull ServerCustomAssertionHolder serverCustomAssertionHolder, @NotNull PolicyEnforcementContext policyEnforcementContext, @Nullable Map map, @Nullable m m2, o o2) throws IOException {
        if (policyEnforcementContext == null) {
            l.a(0);
        }
        if (map == null) {
            l.a(1);
        }
        this.this$0 = serverCustomAssertionHolder;
        super(serverCustomAssertionHolder);
        this.a = policyEnforcementContext;
        this.c = serverCustomAssertionHolder.a(policyEnforcementContext);
        this.d = map;
        Vector vector = serverCustomAssertionHolder.a(policyEnforcementContext.getRequest().getHttpCookiesKnob().getCookies());
        try {
            this.d.put(e[1], vector);
            this.d.put(e[3], Collections.unmodifiableCollection(new ArrayList(vector)));
            if (m2 != null) {
                this.d.put(e[9], m2);
            }
        }
        catch (IOException iOException) {
            throw l.a(iOException);
        }
        try {
            if (o2 != null) {
                this.d.put(e[10], o2);
            }
        }
        catch (IOException iOException) {
            throw l.a(iOException);
        }
        this.b = new j(this, serverCustomAssertionHolder, policyEnforcementContext);
    }

    @Override
    public void onCompletion() {
        this.this$0.b(this.a, this.d);
    }

    public SecurityContext getSecurityContext() {
        return this.b;
    }

    public Map getContext() {
        return this.d;
    }

    public Object getVariable(String string) {
        return this.this$0.a(this.a, string);
    }

    public String expandVariable(String string) {
        Map<String, Object> map = this.getVariableMap(Syntax.getReferencedNames((String)string));
        return this.expandVariable(string, map);
    }

    public String expandVariable(String string, Map<String, Object> map) {
        try {
            if (string == null) {
                return null;
            }
        }
        catch (VariableNotSettableException variableNotSettableException) {
            throw l.a((Exception)((Object)variableNotSettableException));
        }
        return ExpandVariables.process(string, map, this.this$0.getAudit());
    }

    public Map<String, Object> getVariableMap(String[] stringArray) {
        return this.a.getVariableMap(stringArray, this.this$0.getAudit());
    }

    public void setVariable(String string, Object object) {
        this.this$0.a(this.a, string, object);
    }

    public CustomMessageFormatFactory getFormats() {
        return this.this$0.j;
    }

    public CustomMessage getTargetMessage(CustomMessageTargetable customMessageTargetable) throws NoSuchVariableException, VariableNotSettableException {
        try {
            if (customMessageTargetable == null) {
                throw new NoSuchVariableException(e[2], e[5]);
            }
        }
        catch (NoSuchVariableException noSuchVariableException) {
            throw l.a((Exception)((Object)noSuchVariableException));
        }
        CustomToMessageTargetableAdaptor customToMessageTargetableAdaptor = new CustomToMessageTargetableAdaptor(customMessageTargetable);
        Message message = this.a.getOrCreateTargetMessage((MessageTargetable)customToMessageTargetableAdaptor, false);
        CustomMessageImpl customMessageImpl = new CustomMessageImpl(this.getFormats(), message);
        this.this$0.doAttachKnobs(customMessageImpl);
        return customMessageImpl;
    }

    public CustomMessage getMessage(String string) throws NoSuchVariableException, VariableNotSettableException {
        return this.getTargetMessage((CustomMessageTargetable)new CustomMessageTargetableSupport(string));
    }

    public boolean isPostRouting() {
        return this.c;
    }

    public CustomContentType createContentType(String string) throws IOException {
        return new ContentTypeHeaderToCustomConverter(ContentTypeHeader.parseValue((String)string));
    }

    /*
     * Exception decompiling
     */
    private static void a(int var0) {
        /*
         * 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 [0[TRYBLOCK]], but top level block is 1[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 static Exception a(Exception exception) {
        return exception;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[11];
                var3_1 = 0;
                var2_2 = "Wl\u0019Kk*\u000e\u001eu\u0013CkqZ(j\u0018IvqM\u0006WK\"nS*\u000f\u0004w\u001eEvz_\u0007F\u0018Mt}[\u0018$\bj\u001a\rs#J\u000ef\u001f\rlqL\u001d`\u0005\ro{R\u0002f\u000e\r~gM\u000ew\u0003Kpz\u0011\u0007\u0013?d\u0005Ez`\u001e\u0005d\u001aG?}MKk\u0002Ns\r\u001bj\u001bK|m}\u0004k\u0003Gg`>*w\u0010WrqP\u001f%\u0011Mm4~%j\u0003ljxRKu\u0016P~y[\u001f`\u0005\u000281ML%\u0018D?1ME \u0004\u0002raM\u001f%\u0019Mk4\\\u000e%\u0019Wsx\u0011\u000f`\u0011CjxJ(j\u0019VzlJ&d\u0007";
                var4_3 = "Wl\u0019Kk*\u000e\u001eu\u0013CkqZ(j\u0018IvqM\u0006WK\"nS*\u000f\u0004w\u001eEvz_\u0007F\u0018Mt}[\u0018$\bj\u001a\rs#J\u000ef\u001f\rlqL\u001d`\u0005\ro{R\u0002f\u000e\r~gM\u000ew\u0003Kpz\u0011\u0007\u0013?d\u0005Ez`\u001e\u0005d\u001aG?}MKk\u0002Ns\r\u001bj\u001bK|m}\u0004k\u0003Gg`>*w\u0010WrqP\u001f%\u0011Mm4~%j\u0003ljxRKu\u0016P~y[\u001f`\u0005\u000281ML%\u0018D?1ME \u0004\u0002raM\u001f%\u0019Mk4\\\u000e%\u0019Wsx\u0011\u000f`\u0011CjxJ(j\u0019VzlJ&d\u0007".length();
                var1_4 = 6;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = l.a(v0, l.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "$];jGZw\b$]9oMGp3";
                    var4_3 = "$];jGZw\b$]9oMGp3".length();
                    var1_4 = 7;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 21;
                        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++] = l.a(v0, l.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;
            }
        }
        l.e = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x16);
        }
        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 -> 67;
                    case 1 -> 45;
                    case 2 -> 95;
                    case 3 -> 10;
                    case 4 -> 55;
                    case 5 -> 60;
                    default -> 22;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

