/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.util.Functions$UnaryVoid
 *  com.l7tech.util.Pair
 */
package com.l7tech.server.security.keystore.ncipher;

import com.l7tech.server.security.keystore.KeystoreFile;
import com.l7tech.server.security.keystore.ncipher.NcipherKeyStoreData;
import com.l7tech.server.security.keystore.ncipher.NcipherSsgKeyStore;
import com.l7tech.util.Functions;
import com.l7tech.util.Pair;
import java.security.KeyStore;
import java.security.KeyStoreException;

class d
implements Functions.UnaryVoid<KeystoreFile> {
    final NcipherSsgKeyStore this$0;
    private static final String a = d.a(37, d.a("\n\u001fY?\u0012\u0010((\u0014I8\u000f\u001e6\u00068T"));

    d(NcipherSsgKeyStore ncipherSsgKeyStore) {
        this.this$0 = ncipherSsgKeyStore;
    }

    public void call(KeystoreFile keystoreFile) {
        try {
            Pair<NcipherKeyStoreData, KeyStore> pair;
            block5: {
                byte[] byArray;
                block4: {
                    byArray = keystoreFile.getDatabytes();
                    try {
                        if (byArray != null && byArray.length >= 1) break block4;
                    }
                    catch (KeyStoreException keyStoreException) {
                        throw d.a(keyStoreException);
                    }
                    pair = this.this$0.d();
                    break block5;
                }
                pair = this.this$0.a(byArray);
            }
            this.this$0.t = (NcipherKeyStoreData)pair.left;
            this.this$0.s = (KeyStore)pair.right;
            this.this$0.v = System.currentTimeMillis();
            keystoreFile.setProperty(a, this.this$0.t.keystoreMetadata);
            keystoreFile.setDatabytes(this.this$0.a(this.this$0.t, this.this$0.s));
        }
        catch (KeyStoreException keyStoreException) {
            throw new RuntimeException(keyStoreException);
        }
    }

    private static KeyStoreException a(KeyStoreException keyStoreException) {
        return keyStoreException;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x61);
        }
        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 -> 70;
                    case 1 -> 84;
                    case 2 -> 21;
                    case 3 -> 110;
                    case 4 -> 94;
                    case 5 -> 84;
                    default -> 97;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

