/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.policy.assertion.xmlsec.RequireWssEncryptedElement
 *  com.l7tech.security.token.EncryptedElement
 *  com.l7tech.security.token.ParsedElement
 *  com.l7tech.security.xml.processor.ProcessorResult
 *  org.springframework.context.ApplicationContext
 */
package com.l7tech.server.policy.assertion.xmlsec;

import com.l7tech.policy.assertion.xmlsec.RequireWssEncryptedElement;
import com.l7tech.security.token.EncryptedElement;
import com.l7tech.security.token.ParsedElement;
import com.l7tech.security.xml.processor.ProcessorResult;
import com.l7tech.server.policy.assertion.xmlsec.ServerRequireWssOperation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.context.ApplicationContext;

public class ServerRequireWssEncryptedElement
extends ServerRequireWssOperation<RequireWssEncryptedElement> {
    private static final String h = ServerRequireWssEncryptedElement.d(74, ServerRequireWssEncryptedElement.a("N\u000fY(b\u0019XN\u0005"));

    public ServerRequireWssEncryptedElement(RequireWssEncryptedElement requireWssEncryptedElement, ApplicationContext applicationContext) {
        super(requireWssEncryptedElement, applicationContext);
    }

    @Override
    protected String getPastTenseOperationName() {
        return h;
    }

    @Override
    protected ParsedElement[] getElementsFoundByProcessor(ProcessorResult processorResult) {
        if (processorResult == null) {
            return new ParsedElement[0];
        }
        EncryptedElement[] encryptedElementArray = processorResult.getElementsThatWereEncrypted();
        if (encryptedElementArray.length == 0) {
            return encryptedElementArray;
        }
        RequireWssEncryptedElement requireWssEncryptedElement = (RequireWssEncryptedElement)this.assertion;
        List<String> list = requireWssEncryptedElement.getXEncAlgorithmList();
        if (list == null) {
            list = Collections.singletonList(requireWssEncryptedElement.getXEncAlgorithm());
        }
        ArrayList<EncryptedElement> arrayList = new ArrayList<EncryptedElement>();
        for (int i2 = encryptedElementArray.length - 1; i2 >= 0; --i2) {
            EncryptedElement encryptedElement = encryptedElementArray[i2];
            if (!list.contains(encryptedElement.getAlgorithm())) continue;
            arrayList.add(encryptedElement);
        }
        return arrayList.toArray(new ParsedElement[arrayList.size()]);
    }

    @Override
    protected boolean isAllowIfEmpty() {
        return true;
    }

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String d(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 -> 97;
                    case 1 -> 43;
                    case 2 -> 112;
                    case 3 -> 16;
                    case 4 -> 81;
                    case 5 -> 35;
                    default -> 102;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

