/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.security.password.SecurePassword
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.policy.assertion.ext.ServiceException
 *  com.l7tech.policy.assertion.ext.password.SecurePasswordServices
 */
package com.l7tech.server.policy;

import com.l7tech.gateway.common.security.password.SecurePassword;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.policy.assertion.ext.ServiceException;
import com.l7tech.policy.assertion.ext.password.SecurePasswordServices;
import com.l7tech.server.security.password.SecurePasswordManager;
import java.text.ParseException;

public class SecurePasswordServicesImpl
implements SecurePasswordServices {
    private final SecurePasswordManager a;
    private static final String[] b;

    public SecurePasswordServicesImpl(SecurePasswordManager securePasswordManager) {
        this.a = securePasswordManager;
    }

    public String decryptPassword(String string) throws ServiceException {
        try {
            SecurePassword securePassword = (SecurePassword)this.a.findByPrimaryKey(new Goid(string));
            try {
                if (securePassword == null) {
                    throw new ServiceException(b[1] + string + b[0]);
                }
            }
            catch (FindException findException) {
                throw SecurePasswordServicesImpl.a(findException);
            }
            return new String(this.a.decryptPassword(securePassword.getEncodedPassword()));
        }
        catch (FindException | ParseException throwable) {
            throw new ServiceException(throwable);
        }
    }

    private static FindException a(FindException findException) {
        return findException;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[2];
        int n2 = 0;
        String string = "Z]E_R}+\u000f]N\u0005\u0011*RYX\u0005t6\u001e\u0013]B\u0006sd3w\n";
        int n3 = "Z]E_R}+\u000f]N\u0005\u0011*RYX\u0005t6\u001e\u0013]B\u0006sd3w\n".length();
        int n4 = 11;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = SecurePasswordServicesImpl.a(64, SecurePasswordServicesImpl.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                b = stringArray;
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 4);
        }
        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 -> 58;
                    case 1 -> 115;
                    case 2 -> 106;
                    case 3 -> 107;
                    case 4 -> 50;
                    case 5 -> 91;
                    default -> 4;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

