package com.l7tech.server.policy.assertion.xmlsec;

import com.l7tech.message.Message;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.policy.assertion.xmlsec.WssSignElement;
import com.l7tech.security.xml.decorator.DecorationRequirements;
import com.l7tech.server.message.AuthenticationContext;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.xml.InvalidXpathException;
import com.l7tech.xml.xpath.DeferredFailureDomCompiledXpathHolder;
import java.io.IOException;
import org.springframework.context.ApplicationContext;
import org.w3c.dom.Document;

public class ServerWssSignElement extends ServerAddWssSignature<WssSignElement> {
   private final DeferredFailureDomCompiledXpathHolder d;
   private static final String e;

   public ServerWssSignElement(WssSignElement var1, ApplicationContext var2) throws IOException {
      super(var1, var2, true);
      this.d = new DeferredFailureDomCompiledXpathHolder(var1.getXpathExpression());
   }

   @Override
   protected int addDecorationRequirements(
      PolicyEnforcementContext param1, AuthenticationContext param2, Document param3, DecorationRequirements param4, Message param5
   ) throws PolicyAssertionException {
      // $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 0
      // 01: getfield com/l7tech/server/policy/assertion/xmlsec/ServerWssSignElement.d Lcom/l7tech/xml/xpath/DeferredFailureDomCompiledXpathHolder;
      // 04: invokevirtual com/l7tech/xml/xpath/DeferredFailureDomCompiledXpathHolder.getCompiledXpath ()Lcom/l7tech/xml/xpath/DomCompiledXpath;
      // 07: aload 3
      // 08: new com/l7tech/server/util/xml/PolicyEnforcementContextXpathVariableFinder
      // 0b: dup
      // 0c: aload 1
      // 0d: invokespecial com/l7tech/server/util/xml/PolicyEnforcementContextXpathVariableFinder.<init> (Lcom/l7tech/server/message/PolicyEnforcementContext;)V
      // 10: invokevirtual com/l7tech/xml/xpath/DomCompiledXpath.rawSelectElements (Lorg/w3c/dom/Document;Lcom/l7tech/xml/xpath/XpathVariableFinder;)Ljava/util/List;
      // 13: astore 6
      // 15: goto 46
      // 18: astore 7
      // 1a: aload 0
      // 1b: getstatic com/l7tech/gateway/common/audit/AssertionMessages.XPATH_PATTERN_INVALID_MORE_INFO Lcom/l7tech/gateway/common/audit/Messages$M;
      // 1e: bipush 1
      // 1f: anewarray 135
      // 22: dup
      // 23: bipush 0
      // 24: aload 7
      // 26: invokestatic com/l7tech/util/ExceptionUtils.getMessage (Ljava/lang/Throwable;)Ljava/lang/String;
      // 29: getstatic com/l7tech/server/policy/assertion/xmlsec/ServerWssSignElement.e Ljava/lang/String;
      // 2c: swap
      // 2d: invokedynamic makeConcatWithConstants (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; bsm=java/lang/invoke/StringConcatFactory.makeConcatWithConstants (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite; args=[ "\u0001\u0001" ]
      // 32: aastore
      // 33: aload 7
      // 35: invokestatic com/l7tech/util/ExceptionUtils.getDebugException (Ljava/lang/Throwable;)Ljava/lang/Throwable;
      // 38: invokevirtual com/l7tech/server/policy/assertion/xmlsec/ServerWssSignElement.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;Ljava/lang/Throwable;)V
      // 3b: new com/l7tech/server/policy/assertion/AssertionStatusException
      // 3e: dup
      // 3f: getstatic com/l7tech/policy/assertion/AssertionStatus.SERVER_ERROR Lcom/l7tech/policy/assertion/AssertionStatus;
      // 42: invokespecial com/l7tech/server/policy/assertion/AssertionStatusException.<init> (Lcom/l7tech/policy/assertion/AssertionStatus;)V
      // 45: athrow
      // 46: aload 6
      // 48: ifnull 5d
      // 4b: aload 6
      // 4d: invokeinterface java/util/List.size ()I 1
      // 52: bipush 1
      // 53: if_icmpge 63
      // 56: goto 5d
      // 59: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerWssSignElement.a (Lcom/l7tech/xml/InvalidXpathException;)Lcom/l7tech/xml/InvalidXpathException;
      // 5c: athrow
      // 5d: bipush 0
      // 5e: ireturn
      // 5f: invokestatic com/l7tech/server/policy/assertion/xmlsec/ServerWssSignElement.a (Lcom/l7tech/xml/InvalidXpathException;)Lcom/l7tech/xml/InvalidXpathException;
      // 62: athrow
      // 63: aload 4
      // 65: invokevirtual com/l7tech/security/xml/decorator/DecorationRequirements.getElementsToSign ()Ljava/util/Set;
      // 68: aload 6
      // 6a: invokeinterface java/util/Set.addAll (Ljava/util/Collection;)Z 2
      // 6f: pop
      // 70: aload 4
      // 72: bipush 1
      // 73: invokevirtual com/l7tech/security/xml/decorator/DecorationRequirements.setSignTimestamp (Z)V
      // 76: aload 6
      // 78: invokeinterface java/util/List.size ()I 1
      // 7d: ireturn
      // try (0 -> 10): 11 com/l7tech/xml/InvalidXpathException
      // try (32 -> 38): 39 com/l7tech/xml/InvalidXpathException
      // try (34 -> 43): 43 com/l7tech/xml/InvalidXpathException
   }

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

   static {
      String var10002 = c(124, a("S>:aU\u0002\u0003}\u000f7`\\V\u000fd\u0000{pOP\tyT{"));
      byte var10001 = -1;
      e = var10002;
   }

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

      return var10000;
   }

   private static String c(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 -> 119;
            case 1 -> 18;
            case 2 -> 39;
            case 3 -> 105;
            case 4 -> 65;
            case 5 -> 94;
            default -> 26;
         });
      }

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