package com.l7tech.server.search.processors;

import com.l7tech.objectmodel.EntityHeader;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.policy.assertion.xmlsec.LookupTrustedCertificateAssertion;
import com.l7tech.policy.assertion.xmlsec.LookupTrustedCertificateAssertion.LookupType;
import com.l7tech.security.cert.TrustedCert;
import com.l7tech.security.cert.TrustedCertManager;
import com.l7tech.server.search.exceptions.CannotReplaceDependenciesException;
import com.l7tech.server.search.exceptions.CannotRetrieveDependenciesException;
import com.l7tech.server.search.objects.Dependency;
import com.l7tech.util.Functions;
import jakarta.inject.Inject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.NotNull;

public class AssertionLookupTrustedCertificateProcessor implements DependencyProcessor<LookupTrustedCertificateAssertion> {
   @Inject
   private TrustedCertManager trustedCertManager;
   private static final String[] a;

   @NotNull
   public List<Dependency> findDependencies(@NotNull LookupTrustedCertificateAssertion var1, @NotNull DependencyFinder var2) throws FindException, CannotRetrieveDependenciesException {
      try {
         if (var1 == null) {
            a(0);
         }
      } catch (FindException var6) {
         throw a(var6);
      }

      try {
         if (var2 == null) {
            a(1);
         }
      } catch (FindException var8) {
         throw a(var8);
      }

      Collection var3 = this.a(var1);
      ArrayList var4 = new ArrayList();

      try {
         if (!var3.isEmpty()) {
            var4.addAll(var2.getDependenciesFromObjects(var1, var2, Functions.map(var3, new c(this))));
         }
      } catch (FindException var7) {
         throw a(var7);
      }

      try {
         if (var4 == null) {
            a(2);
         }

         return var4;
      } catch (FindException var5) {
         throw a(var5);
      }
   }

   @NotNull
   private Collection<TrustedCert> a(@NotNull LookupTrustedCertificateAssertion param1) throws FindException, CannotRetrieveDependenciesException {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.RuntimeException: parsing failure!
      //   at org.jetbrains.java.decompiler.modules.decompiler.decompose.DomHelper.parseGraph(DomHelper.java:211)
      //   at org.jetbrains.java.decompiler.main.rels.MethodProcessor.codeToJava(MethodProcessor.java:174)
      //
      // Bytecode:
      // 00: aload 1
      // 01: ifnonnull 0f
      // 04: bipush 3
      // 05: invokestatic com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.a (I)V
      // 08: goto 0f
      // 0b: invokestatic com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 0e: athrow
      // 0f: getstatic com/l7tech/server/search/processors/d.a [I
      // 12: aload 1
      // 13: invokevirtual com/l7tech/policy/assertion/xmlsec/LookupTrustedCertificateAssertion.getLookupType ()Lcom/l7tech/policy/assertion/xmlsec/LookupTrustedCertificateAssertion$LookupType;
      // 16: invokevirtual com/l7tech/policy/assertion/xmlsec/LookupTrustedCertificateAssertion$LookupType.ordinal ()I
      // 19: iaload
      // 1a: tableswitch 170 1 5 34 81 110 140 170
      // 3c: aload 0
      // 3d: getfield com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.trustedCertManager Lcom/l7tech/security/cert/TrustedCertManager;
      // 40: new javax/security/auth/x500/X500Principal
      // 43: dup
      // 44: aload 1
      // 45: invokevirtual com/l7tech/policy/assertion/xmlsec/LookupTrustedCertificateAssertion.getCertIssuerDn ()Ljava/lang/String;
      // 48: invokespecial javax/security/auth/x500/X500Principal.<init> (Ljava/lang/String;)V
      // 4b: new java/math/BigInteger
      // 4e: dup
      // 4f: aload 1
      // 50: invokevirtual com/l7tech/policy/assertion/xmlsec/LookupTrustedCertificateAssertion.getCertSerialNumber ()Ljava/lang/String;
      // 53: invokespecial java/math/BigInteger.<init> (Ljava/lang/String;)V
      // 56: invokeinterface com/l7tech/security/cert/TrustedCertManager.findByIssuerAndSerial (Ljavax/security/auth/x500/X500Principal;Ljava/math/BigInteger;)Ljava/util/List; 3
      // 5b: dup
      // 5c: ifnonnull 6a
      // 5f: goto 66
      // 62: invokestatic com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 65: athrow
      // 66: bipush 4
      // 67: invokestatic com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.a (I)V
      // 6a: areturn
      // 6b: aload 0
      // 6c: getfield com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.trustedCertManager Lcom/l7tech/security/cert/TrustedCertManager;
      // 6f: aload 1
      // 70: invokevirtual com/l7tech/policy/assertion/xmlsec/LookupTrustedCertificateAssertion.getCertSubjectKeyIdentifier ()Ljava/lang/String;
      // 73: invokeinterface com/l7tech/security/cert/TrustedCertManager.findBySki (Ljava/lang/String;)Ljava/util/List; 2
      // 78: dup
      // 79: ifnonnull 87
      // 7c: bipush 5
      // 7d: invokestatic com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.a (I)V
      // 80: goto 87
      // 83: invokestatic com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // 86: athrow
      // 87: areturn
      // 88: aload 0
      // 89: getfield com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.trustedCertManager Lcom/l7tech/security/cert/TrustedCertManager;
      // 8c: aload 1
      // 8d: invokevirtual com/l7tech/policy/assertion/xmlsec/LookupTrustedCertificateAssertion.getCertSubjectDn ()Ljava/lang/String;
      // 90: invokeinterface com/l7tech/security/cert/TrustedCertManager.findBySubjectDn (Ljava/lang/String;)Ljava/util/Collection; 2
      // 95: dup
      // 96: ifnonnull a5
      // 99: bipush 6
      // 9b: invokestatic com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.a (I)V
      // 9e: goto a5
      // a1: invokestatic com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // a4: athrow
      // a5: areturn
      // a6: aload 0
      // a7: getfield com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.trustedCertManager Lcom/l7tech/security/cert/TrustedCertManager;
      // aa: aload 1
      // ab: invokevirtual com/l7tech/policy/assertion/xmlsec/LookupTrustedCertificateAssertion.getCertThumbprintSha1 ()Ljava/lang/String;
      // ae: invokeinterface com/l7tech/security/cert/TrustedCertManager.findByThumbprint (Ljava/lang/String;)Ljava/util/List; 2
      // b3: dup
      // b4: ifnonnull c3
      // b7: bipush 7
      // b9: invokestatic com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.a (I)V
      // bc: goto c3
      // bf: invokestatic com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // c2: athrow
      // c3: areturn
      // c4: aload 0
      // c5: getfield com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.trustedCertManager Lcom/l7tech/security/cert/TrustedCertManager;
      // c8: aload 1
      // c9: invokevirtual com/l7tech/policy/assertion/xmlsec/LookupTrustedCertificateAssertion.getTrustedCertificateName ()Ljava/lang/String;
      // cc: invokeinterface com/l7tech/security/cert/TrustedCertManager.findByName (Ljava/lang/String;)Ljava/util/Collection; 2
      // d1: dup
      // d2: ifnonnull e1
      // d5: bipush 8
      // d7: invokestatic com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.a (I)V
      // da: goto e1
      // dd: invokestatic com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // e0: athrow
      // e1: areturn
      // e2: astore 2
      // e3: invokestatic java/util/Collections.emptyList ()Ljava/util/List;
      // e6: dup
      // e7: ifnonnull f6
      // ea: bipush 9
      // ec: invokestatic com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.a (I)V
      // ef: goto f6
      // f2: invokestatic com/l7tech/server/search/processors/AssertionLookupTrustedCertificateProcessor.a (Ljava/lang/Exception;)Ljava/lang/Exception;
      // f5: athrow
      // f6: areturn
      // try (0 -> 4): 5 java/lang/IllegalArgumentException
      // try (7 -> 26): 86 java/lang/IllegalArgumentException
      // try (7 -> 28): 29 com/l7tech/objectmodel/FindException
      // try (34 -> 39): 86 java/lang/IllegalArgumentException
      // try (34 -> 43): 44 com/l7tech/objectmodel/FindException
      // try (47 -> 52): 86 java/lang/IllegalArgumentException
      // try (47 -> 56): 57 com/l7tech/objectmodel/FindException
      // try (60 -> 65): 86 java/lang/IllegalArgumentException
      // try (60 -> 69): 70 com/l7tech/objectmodel/FindException
      // try (73 -> 78): 86 java/lang/IllegalArgumentException
      // try (73 -> 82): 83 com/l7tech/objectmodel/FindException
      // try (87 -> 92): 93 java/lang/IllegalArgumentException
   }

   public void replaceDependencies(
      @NotNull LookupTrustedCertificateAssertion var1, @NotNull Map<EntityHeader, EntityHeader> var2, @NotNull DependencyFinder var3, boolean var4
   ) throws CannotReplaceDependenciesException {
      try {
         if (var1 == null) {
            a(10);
         }
      } catch (CannotReplaceDependenciesException var9) {
         throw a(var9);
      }

      try {
         if (var2 == null) {
            a(11);
         }
      } catch (CannotReplaceDependenciesException var11) {
         throw a(var11);
      }

      try {
         if (var3 == null) {
            a(12);
         }
      } catch (CannotReplaceDependenciesException var8) {
         throw a(var8);
      }

      try {
         if (!var4) {
            return;
         }
      } catch (CannotReplaceDependenciesException var10) {
         throw a(var10);
      }

      if (var1.getLookupType().equals(LookupType.TRUSTED_CERT_NAME)) {
         EntityHeader var5 = new EntityHeader(Goid.DEFAULT_GOID, EntityType.TRUSTED_CERT, var1.getTrustedCertificateName(), "");
         EntityHeader var6 = DependencyProcessorUtils.findMappedHeader(var2, var5);

         try {
            if (var6 != null) {
               var1.setTrustedCertificateName(var6.getName());
            }
         } catch (CannotReplaceDependenciesException var7) {
            throw a(var7);
         }
      }
   }

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

   static {
      String[] var5 = new String[12];
      int var3 = 0;
      String var2 = "\u0004-\u0004\\TH@1\u007f\u0005FK\rn\u000b0\u0017gLABe/\u0002[X@K1:\u0011\t\u001e\b]b\u007f\fO\u0019\b]kz\u0010\tTX]1\u007f\rFM\rL \u007f\r\\UAN&0\u000e\u0006U\u001aZ <\u000b\u0006JH\\3:\u0011\u0006JHO7<\u000b\u0006I_A&:\u0010ZV_]j\u001e\u0010Z\\_Z,0\reVBE0/7[L^Z ; LKYG#6\u0000HMH~70\u0000LJ^A7\u0010#6\rM}H^ 1\u0007LWNG ,\u0010#6\rM}H^ 1\u0007LWNG ,*\u0005\u0011\f]wXB)\u007f\u000eLMEA!\u007fFZ\u0017\b]e2\u0016ZM\r@*+C[\\Y[71CGLABN&0\u000e\u0006U\u001aZ <\u000b\u0006JH\\3:\u0011\u0006JHO7<\u000b\u0006I_A&:\u0010ZV_]j\u001e\u0010Z\\_Z,0\reVBE0/7[L^Z ; LKYG#6\u0000HMH~70\u0000LJ^A7\u0013\":\u0017j\\_Z,9\nJXYK6\n\u0010L]\t$,\u0010LKYG*1\u000e7:\u0013EXNK(:\r]tL^\u0013\":\u0017j\\_Z,9\nJXYK6\n\u0010L]";
      int var4 = "\u0004-\u0004\\TH@1\u007f\u0005FK\rn\u000b0\u0017gLABe/\u0002[X@K1:\u0011\t\u001e\b]b\u007f\fO\u0019\b]kz\u0010\tTX]1\u007f\rFM\rL \u007f\r\\UAN&0\u000e\u0006U\u001aZ <\u000b\u0006JH\\3:\u0011\u0006JHO7<\u000b\u0006I_A&:\u0010ZV_]j\u001e\u0010Z\\_Z,0\reVBE0/7[L^Z ; LKYG#6\u0000HMH~70\u0000LJ^A7\u0010#6\rM}H^ 1\u0007LWNG ,\u0010#6\rM}H^ 1\u0007LWNG ,*\u0005\u0011\f]wXB)\u007f\u000eLMEA!\u007fFZ\u0017\b]e2\u0016ZM\r@*+C[\\Y[71CGLABN&0\u000e\u0006U\u001aZ <\u000b\u0006JH\\3:\u0011\u0006JHO7<\u000b\u0006I_A&:\u0010ZV_]j\u001e\u0010Z\\_Z,0\reVBE0/7[L^Z ; LKYG#6\u0000HMH~70\u0000LJ^A7\u0013\":\u0017j\\_Z,9\nJXYK6\n\u0010L]\t$,\u0010LKYG*1\u000e7:\u0013EXNK(:\r]tL^\u0013\":\u0017j\\_Z,9\nJXYK6\n\u0010L]"
         .length();
      char var1 = '>';
      int var7 = -1;

      label24:
      while (true) {
         byte var10000 = 10;
         String var10001 = var2.substring(++var7, var7 + var1);
         byte var10002 = -1;

         while (true) {
            String var8 = a(var10000, a(var10001));
            switch (var10002) {
               case 0:
                  var5[var3++] = var8;
                  if ((var7 += var1) >= var4) {
                     a = var5;
                     return;
                  }

                  var1 = var2.charAt(var7);
                  break;
               default:
                  var5[var3++] = var8;
                  if ((var7 += var1) < var4) {
                     var1 = var2.charAt(var7);
                     continue label24;
                  }

                  var2 = "v{R\u0004\u0019\u000f\n@{R\r\u0016\b\nj}K\r\u000b\u0006bwL\f\u001d\u001e";
                  var4 = "v{R\u0004\u0019\u000f\n@{R\r\u0016\b\nj}K\r\u000b\u0006bwL\f\u001d\u001e".length();
                  var1 = 19;
                  var7 = -1;
            }

            var10000 = 75;
            var10001 = var2.substring(++var7, var7 + var1);
            var10002 = 0;
         }
      }
   }

   private static char[] a(String var0) {
      char[] var10000 = var0.toCharArray();
      if (var10000.length < 2) {
         var10000[0] = (char)(var10000[0] ^ 36);
      }

      return var10000;
   }

   private static String a(int var0, char[] var1) {
      int var10003 = var1.length;
      int var10002 = var0;
      char[] var10001 = var1;
      int var10000 = var10003;

      for (int var2 = 0; var10000 > var2; var2++) {
         var10001[var2] = (char)(var10001[var2] ^ var10002 ^ switch (var2 % 7) {
            case 0 -> 79;
            case 1 -> 85;
            case 2 -> 105;
            case 3 -> 35;
            case 4 -> 51;
            case 5 -> 39;
            default -> 36;
         });
      }

      return new String(var10001).intern();
   }
}
