package com.l7tech.server.policy.assertion;

import com.l7tech.common.mime.NoSuchPartException;
import com.l7tech.gateway.common.audit.Audit;
import com.l7tech.gateway.common.audit.AuditFactory;
import com.l7tech.message.Message;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.MessageBufferingAssertion;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.server.message.AuthenticationContext;
import com.l7tech.server.message.PolicyEnforcementContext;
import java.io.IOException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ServerMessageBufferingAssertion extends AbstractMessageTargetableServerAssertion<MessageBufferingAssertion> {
   private static final String[] d;

   public ServerMessageBufferingAssertion(@NotNull MessageBufferingAssertion var1) {
      if (var1 == null) {
         c(0);
      }

      super(var1);
   }

   public ServerMessageBufferingAssertion(@NotNull MessageBufferingAssertion var1, @Nullable AuditFactory var2) {
      if (var1 == null) {
         c(1);
      }

      super(var1, var2);
   }

   @Override
   protected AssertionStatus doCheckRequest(PolicyEnforcementContext var1, Message var2, String var3, AuthenticationContext var4) throws IOException, PolicyAssertionException {
      return configureMessageBuffering(this.assertion.isNeverBuffer(), this.assertion.isAlwaysBuffer(), var2, var3, this.getAudit());
   }

   protected static AssertionStatus configureMessageBuffering(boolean param0, boolean param1, Message param2, String param3, Audit param4) throws IOException {
      // $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 2
      // 01: invokevirtual com/l7tech/message/Message.isInitialized ()Z
      // 04: ifne 21
      // 07: aload 4
      // 09: getstatic com/l7tech/gateway/common/audit/AssertionMessages.MESSAGE_NOT_INITIALIZED Lcom/l7tech/gateway/common/audit/Messages$M;
      // 0c: bipush 1
      // 0d: anewarray 33
      // 10: dup
      // 11: bipush 0
      // 12: aload 3
      // 13: aastore
      // 14: invokeinterface com/l7tech/gateway/common/audit/Audit.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V 3
      // 19: getstatic com/l7tech/policy/assertion/AssertionStatus.SERVER_ERROR Lcom/l7tech/policy/assertion/AssertionStatus;
      // 1c: areturn
      // 1d: invokestatic com/l7tech/server/policy/assertion/ServerMessageBufferingAssertion.a (Lcom/l7tech/common/mime/NoSuchPartException;)Lcom/l7tech/common/mime/NoSuchPartException;
      // 20: athrow
      // 21: iload 0
      // 22: ifeq 61
      // 25: aload 2
      // 26: invokevirtual com/l7tech/message/Message.getMimeKnob ()Lcom/l7tech/message/MimeKnob;
      // 29: bipush 1
      // 2a: invokeinterface com/l7tech/message/MimeKnob.setBufferingDisallowed (Z)V 2
      // 2f: aload 2
      // 30: invokevirtual com/l7tech/message/Message.getMimeKnob ()Lcom/l7tech/message/MimeKnob;
      // 33: invokeinterface com/l7tech/message/MimeKnob.getFirstPart ()Lcom/l7tech/common/mime/PartInfo; 1
      // 38: invokeinterface com/l7tech/common/mime/PartInfo.isBodyStashed ()Z 1
      // 3d: ifeq 61
      // 40: goto 47
      // 43: invokestatic com/l7tech/server/policy/assertion/ServerMessageBufferingAssertion.a (Lcom/l7tech/common/mime/NoSuchPartException;)Lcom/l7tech/common/mime/NoSuchPartException;
      // 46: athrow
      // 47: aload 4
      // 49: getstatic com/l7tech/gateway/common/audit/AssertionMessages.MESSAGE_ALREADY_BUFFERED Lcom/l7tech/gateway/common/audit/Messages$M;
      // 4c: bipush 1
      // 4d: anewarray 33
      // 50: dup
      // 51: bipush 0
      // 52: aload 3
      // 53: aastore
      // 54: invokeinterface com/l7tech/gateway/common/audit/Audit.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V 3
      // 59: getstatic com/l7tech/policy/assertion/AssertionStatus.FAILED Lcom/l7tech/policy/assertion/AssertionStatus;
      // 5c: areturn
      // 5d: invokestatic com/l7tech/server/policy/assertion/ServerMessageBufferingAssertion.a (Lcom/l7tech/common/mime/NoSuchPartException;)Lcom/l7tech/common/mime/NoSuchPartException;
      // 60: athrow
      // 61: iload 1
      // 62: ifeq c9
      // 65: aload 2
      // 66: invokevirtual com/l7tech/message/Message.getMimeKnob ()Lcom/l7tech/message/MimeKnob;
      // 69: bipush 0
      // 6a: invokeinterface com/l7tech/message/MimeKnob.setBufferingDisallowed (Z)V 2
      // 6f: aconst_null
      // 70: astore 5
      // 72: aload 2
      // 73: invokevirtual com/l7tech/message/Message.getMimeKnob ()Lcom/l7tech/message/MimeKnob;
      // 76: bipush 0
      // 77: invokeinterface com/l7tech/message/MimeKnob.getEntireMessageBodyAsInputStream (Z)Ljava/io/InputStream; 2
      // 7c: astore 5
      // 7e: aload 5
      // 80: new com/l7tech/common/io/NullOutputStream
      // 83: dup
      // 84: invokespecial com/l7tech/common/io/NullOutputStream.<init> ()V
      // 87: invokestatic com/l7tech/util/IOUtils.copyStream (Ljava/io/InputStream;Ljava/io/OutputStream;)J
      // 8a: pop2
      // 8b: aload 5
      // 8d: invokestatic com/l7tech/util/ResourceUtils.closeQuietly (Ljava/io/Closeable;)V
      // 90: goto c9
      // 93: astore 6
      // 95: aload 4
      // 97: getstatic com/l7tech/gateway/common/audit/AssertionMessages.NO_SUCH_PART Lcom/l7tech/gateway/common/audit/Messages$M;
      // 9a: bipush 2
      // 9b: anewarray 33
      // 9e: dup
      // 9f: bipush 0
      // a0: aload 3
      // a1: aastore
      // a2: dup
      // a3: bipush 1
      // a4: aload 6
      // a6: invokevirtual com/l7tech/common/mime/NoSuchPartException.getOrdinal ()I
      // a9: invokestatic java/lang/String.valueOf (I)Ljava/lang/String;
      // ac: aastore
      // ad: invokeinterface com/l7tech/gateway/common/audit/Audit.logAndAudit (Lcom/l7tech/gateway/common/audit/AuditDetailMessage;[Ljava/lang/String;)V 3
      // b2: getstatic com/l7tech/policy/assertion/AssertionStatus.SERVER_ERROR Lcom/l7tech/policy/assertion/AssertionStatus;
      // b5: astore 7
      // b7: aload 5
      // b9: invokestatic com/l7tech/util/ResourceUtils.closeQuietly (Ljava/io/Closeable;)V
      // bc: aload 7
      // be: areturn
      // bf: astore 8
      // c1: aload 5
      // c3: invokestatic com/l7tech/util/ResourceUtils.closeQuietly (Ljava/io/Closeable;)V
      // c6: aload 8
      // c8: athrow
      // c9: getstatic com/l7tech/policy/assertion/AssertionStatus.NONE Lcom/l7tech/policy/assertion/AssertionStatus;
      // cc: areturn
      // try (18 -> 41): 41 com/l7tech/common/mime/NoSuchPartException
      // try (16 -> 27): 28 com/l7tech/common/mime/NoSuchPartException
      // try (0 -> 14): 14 com/l7tech/common/mime/NoSuchPartException
      // try (51 -> 62): 65 com/l7tech/common/mime/NoSuchPartException
      // try (51 -> 62): 87 null
      // try (65 -> 83): 87 null
      // try (87 -> 88): 87 null
   }

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

   static {
      String[] var5 = new String[4];
      int var3 = 0;
      String var2 = "NH(R2\u0007E@U>nI<B-\u0016B[\u001b=X2SlaT/y5\u001f@\u000fK:E!\u001eI[^)\u0017gV_\b\u001b4Q`V_\u0001\u001e(\u0017-\u0006_[\u001b5X4SNJ\u001b5B,\u001f";
      int var4 = "NH(R2\u0007E@U>nI<B-\u0016B[\u001b=X2SlaT/y5\u001f@\u000fK:E!\u001eI[^)\u0017gV_\b\u001b4Q`V_\u0001\u001e(\u0017-\u0006_[\u001b5X4SNJ\u001b5B,\u001f"
         .length();
      char var1 = '\t';
      int var7 = -1;

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

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

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

                  var2 = "\"c\u0004o\u0005|B}e\u0007)\u001dui{i\u0002)\u0002'oho\u0018)\u0001-qwi\u0013)\u00101n{x\u001eo\u001e,2Mo\u0018p\u00140P{y\u0019g\u0016'_kl\fc\u0003+syK\u0019u\u00140iwe\u0004";
                  var4 = "\"c\u0004o\u0005|B}e\u0007)\u001dui{i\u0002)\u0002'oho\u0018)\u0001-qwi\u0013)\u00101n{x\u001eo\u001e,2Mo\u0018p\u00140P{y\u0019g\u0016'_kl\fc\u0003+syK\u0019u\u00140iwe\u0004"
                     .length();
                  var1 = 6;
                  var7 = -1;
            }

            var10000 = 65;
            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] ^ 92);
      }

      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 -> 95;
            case 1 -> 75;
            case 2 -> 43;
            case 3 -> 71;
            case 4 -> 48;
            case 5 -> 3;
            default -> 92;
         });
      }

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