package org.jivesoftware.smack.util.stringencoder;

import java.io.UnsupportedEncodingException;
import org.jivesoftware.smack.util.Objects;

public class Base64 {
   private static Base64.Encoder base64encoder;

   public static void setEncoder(Base64.Encoder encoder) {
      Objects.requireNonNull(encoder, "encoder must no be null");
      base64encoder = encoder;
   }

   public static final String encode(String string) {
      try {
         return encodeToString(string.getBytes("UTF-8"));
      } catch (UnsupportedEncodingException var2) {
         throw new IllegalStateException("UTF-8 not supported", var2);
      }
   }

   public static final String encodeToString(byte[] input) {
      byte[] bytes = encode(input);

      try {
         return new String(bytes, "US-ASCII");
      } catch (UnsupportedEncodingException var3) {
         throw new AssertionError(var3);
      }
   }

   public static final String encodeToString(byte[] input, int offset, int len) {
      byte[] bytes = encode(input, offset, len);

      try {
         return new String(bytes, "US-ASCII");
      } catch (UnsupportedEncodingException var5) {
         throw new AssertionError(var5);
      }
   }

   public static final byte[] encode(byte[] input) {
      return encode(input, 0, input.length);
   }

   public static final byte[] encode(byte[] input, int offset, int len) {
      return base64encoder.encode(input, offset, len);
   }

   public static final String decodeToString(String string) {
      byte[] bytes = decode(string);

      try {
         return new String(bytes, "UTF-8");
      } catch (UnsupportedEncodingException var3) {
         throw new IllegalStateException("UTF-8 not supported", var3);
      }
   }

   public static final String decodeToString(byte[] input, int offset, int len) {
      byte[] bytes = decode(input, offset, len);

      try {
         return new String(bytes, "UTF-8");
      } catch (UnsupportedEncodingException var5) {
         throw new IllegalStateException("UTF-8 not supported", var5);
      }
   }

   public static final byte[] decode(String string) {
      return base64encoder.decode(string);
   }

   public static final byte[] decode(byte[] input) {
      return base64encoder.decode(input, 0, input.length);
   }

   public static final byte[] decode(byte[] input, int offset, int len) {
      return base64encoder.decode(input, offset, len);
   }

   public interface Encoder {
      byte[] decode(String var1);

      byte[] decode(byte[] var1, int var2, int var3);

      String encodeToString(byte[] var1, int var2, int var3);

      byte[] encode(byte[] var1, int var2, int var3);
   }
}
