/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.springframework.beans.factory.config.PropertiesFactoryBean
 */
package com.l7tech.server.util;

import com.l7tech.server.util.PropertiesDecryptor;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.beans.factory.config.PropertiesFactoryBean;

public class PasswordDecryptingPropertiesFactoryBean
extends PropertiesFactoryBean {
    private static final Logger a;
    private static final String b;
    private static final String c = "}";
    private final PropertiesDecryptor d;
    private String e;
    private String f;
    private static final String[] g;

    public PasswordDecryptingPropertiesFactoryBean(PropertiesDecryptor propertiesDecryptor) {
        String[] stringArray = g;
        this.e = stringArray[3];
        this.f = c;
        this.d = propertiesDecryptor;
        if (propertiesDecryptor == null) {
            throw new IllegalArgumentException(stringArray[2]);
        }
    }

    public void setPlaceholderPrefix(String string) {
        this.e = string;
    }

    public void setPlaceholderSuffix(String string) {
        this.f = string;
    }

    protected Properties mergeProperties() throws IOException {
        Properties properties = super.mergeProperties();
        this.d.decryptEncryptedPasswords(properties);
        this.a(properties);
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            try {
                if (this.d.isPasswordPropertyName(entry.getKey())) {
                    a.log(Level.CONFIG, g[4], entry.getKey());
                    continue;
                }
            }
            catch (IOException iOException) {
                throw PasswordDecryptingPropertiesFactoryBean.a(iOException);
            }
            a.log(Level.CONFIG, g[1], new Object[]{entry.getKey(), entry.getValue()});
        }
        return properties;
    }

    private void a(Properties properties) {
        for (String string : Collections.list(properties.propertyNames())) {
            String string2 = properties.getProperty(string);
            String string3 = this.a(string2, properties, new HashSet<String>());
            properties.setProperty(string, string3);
        }
    }

    private String a(String string, Properties properties, Set<String> set) {
        StringBuffer stringBuffer = new StringBuffer(string);
        int n2 = string.indexOf(this.e);
        while (n2 != -1) {
            int n3 = this.a(stringBuffer, n2);
            if (n3 != -1) {
                String string2 = stringBuffer.substring(n2 + this.e.length(), n3);
                try {
                    if (!set.add(string2)) {
                        break;
                    }
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw PasswordDecryptingPropertiesFactoryBean.a(illegalArgumentException);
                }
                String string3 = properties.getProperty(string2 = this.a(string2, properties, set));
                if (string3 != null) {
                    string3 = this.a(string3, properties, set);
                    stringBuffer.replace(n2, n3 + this.f.length(), string3);
                    n2 = stringBuffer.indexOf(this.e, n2 + string3.length());
                } else {
                    n2 = stringBuffer.indexOf(this.e, n3 + this.f.length());
                }
                set.remove(string2);
                continue;
            }
            n2 = -1;
        }
        return stringBuffer.toString();
    }

    private int a(CharSequence charSequence, int n2) {
        int n3 = n2 + this.e.length();
        int n4 = 0;
        while (true) {
            block6: {
                block7: {
                    try {
                        try {
                            if (n3 >= charSequence.length()) break;
                            if (!PasswordDecryptingPropertiesFactoryBean.substringMatch(charSequence, n3, this.f)) break block6;
                        }
                        catch (IllegalArgumentException illegalArgumentException) {
                            throw PasswordDecryptingPropertiesFactoryBean.a(illegalArgumentException);
                        }
                        if (n4 <= 0) break block7;
                    }
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw PasswordDecryptingPropertiesFactoryBean.a(illegalArgumentException);
                    }
                    --n4;
                    n3 += this.f.length();
                    continue;
                }
                return n3;
            }
            if (PasswordDecryptingPropertiesFactoryBean.substringMatch(charSequence, n3, this.e)) {
                ++n4;
                n3 += this.e.length();
                continue;
            }
            ++n3;
        }
        return -1;
    }

    public static boolean substringMatch(CharSequence charSequence, int n2, CharSequence charSequence2) {
        for (int i2 = 0; i2 < charSequence2.length(); ++i2) {
            int n3 = n2 + i2;
            try {
                try {
                    if (n3 < charSequence.length() && charSequence.charAt(n3) == charSequence2.charAt(i2)) continue;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw PasswordDecryptingPropertiesFactoryBean.a(illegalArgumentException);
                }
                return false;
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw PasswordDecryptingPropertiesFactoryBean.a(illegalArgumentException);
            }
        }
        return true;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[5];
                var3_1 = 0;
                var2_2 = "y\u001e!\b\u00169OU\u0016;/\n D@B2}BwZ\u0002KlzEm\u0001\u0015\u00110l\u0018w\u0006\u001c\"\u001cE\u0000S]F./\u00119DAr.>\u0017)QFY9}\f#\u0001@S:(\f\"DV\u0018";
                var4_3 = "y\u001e!\b\u00169OU\u0016;/\n D@B2}BwZ\u0002KlzEm\u0001\u0015\u00110l\u0018w\u0006\u001c\"\u001cE\u0000S]F./\u00119DAr.>\u0017)QFY9}\f#\u0001@S:(\f\"DV\u0018".length();
                var1_4 = 2;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = PasswordDecryptingPropertiesFactoryBean.a(v0, PasswordDecryptingPropertiesFactoryBean.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "q\u0016\"\u0000\u001e1G]\u001e3'\u0002(LHJ:uJ\u007fR\nCdrMe\t\u0006v\n\u0011)\u001dg\u0004\u0010";
                    var4_3 = "q\u0016\"\u0000\u001e1G]\u001e3'\u0002(LHJ:uJ\u007fR\nCdrMe\t\u0006v\n\u0011)\u001dg\u0004\u0010".length();
                    var1_4 = 2;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 70;
                        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++] = PasswordDecryptingPropertiesFactoryBean.a(v0, PasswordDecryptingPropertiesFactoryBean.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;
            }
        }
        PasswordDecryptingPropertiesFactoryBean.g = var5;
        PasswordDecryptingPropertiesFactoryBean.b = PasswordDecryptingPropertiesFactoryBean.g[0];
        PasswordDecryptingPropertiesFactoryBean.a = Logger.getLogger(PasswordDecryptingPropertiesFactoryBean.class.getName());
    }

    private static Exception a(Exception exception) {
        return exception;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 5);
        }
        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 -> 19;
                    case 1 -> 43;
                    case 2 -> 30;
                    case 3 -> 111;
                    case 4 -> 124;
                    case 5 -> 120;
                    default -> 5;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

