// Path: src/main/java/javapns/communication/exceptions/InvalidKeystoreFormatException.java
// public class InvalidKeystoreFormatException extends KeystoreException {
// 
//   private static final long serialVersionUID = 8822634206752412121L;
// 
//   /**
//    * Constructor
//    */
//   public InvalidKeystoreFormatException() {
//     super("Invalid keystore format!  Make sure it is PKCS12...");
//   }
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param message
//    */
//   public InvalidKeystoreFormatException(final String message) {
//     super(message);
//   }
// 
// }
// 
// Path: src/main/java/javapns/communication/exceptions/InvalidKeystorePasswordException.java
// public class InvalidKeystorePasswordException extends KeystoreException {
// 
//   private static final long serialVersionUID = 5973743951334025887L;
// 
//   /**
//    * Constructor
//    */
//   public InvalidKeystorePasswordException() {
//     super("Invalid keystore password!  Verify settings for connecting to Apple...");
//   }
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param message
//    */
//   public InvalidKeystorePasswordException(final String message) {
//     super(message);
//   }
// 
// }
// 
// Path: src/main/java/javapns/communication/exceptions/InvalidKeystoreReferenceException.java
// public class InvalidKeystoreReferenceException extends KeystoreException {
// 
//   private static final long serialVersionUID = 3144387163593035745L;
// 
//   /**
//    * Constructor
//    */
//   public InvalidKeystoreReferenceException() {
//     super("Invalid keystore parameter.  Must be InputStream, File, String (as a file path), or byte[].");
//   }
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param keystore
//    */
//   public InvalidKeystoreReferenceException(final Object keystore) {
//     super("Invalid keystore parameter (" + keystore + ").  Must be InputStream, File, String (as a file path), or byte[].");
//   }
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param message
//    */
//   public InvalidKeystoreReferenceException(final String message) {
//     super(message);
//   }
// }
// 
// Path: src/main/java/javapns/communication/exceptions/KeystoreException.java
// public class KeystoreException extends Exception {
// 
//   private static final long serialVersionUID = 2549063865160633139L;
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param message
//    */
//   public KeystoreException(final String message) {
//     super(message);
//   }
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param message
//    */
//   public KeystoreException(final String message, final Exception cause) {
//     super(message, cause);
//   }
// 
// }


import javapns.communication.exceptions.InvalidKeystoreFormatException;
import javapns.communication.exceptions.InvalidKeystorePasswordException;
import javapns.communication.exceptions.InvalidKeystoreReferenceException;
import javapns.communication.exceptions.KeystoreException;
import java.io.*;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
import java.security.cert.X509Certificate;
import java.util.Enumeration;

    return password.toCharArray();
  }

  static KeystoreException wrapKeystoreException(final Exception e) {
    if (e != null) {
      final String msg = e.toString();
      if (msg.contains("javax.crypto.BadPaddingException")) {
        return new InvalidKeystorePasswordException();
      }
      if (msg.contains("DerInputStream.getLength(): lengthTag=127, too big")) {
        return new InvalidKeystoreFormatException();
      }
      if (msg.contains("java.lang.ArithmeticException: / by zero") || msg.contains("java.security.UnrecoverableKeyException: Get Key failed: / by zero")) {
        return new InvalidKeystorePasswordException("Blank passwords not supported (#38).  You must create your keystore with a non-empty password.");
      }
    }

    return new KeystoreException("Keystore exception: " + (e != null ? e.getMessage() : null), e);
  }

  /**
   * Given an object representing a keystore, returns an actual stream for that keystore.
   * Allows you to provide an actual keystore as an InputStream or a byte[] array,
   * or a reference to a keystore file as a File object or a String path.
   *
   * @param keystore a keystore containing your private key and the certificate signed by Apple (File, InputStream, byte[], KeyStore or String for a file path)
   * @return A stream to the keystore.
   * @throws InvalidKeystoreReferenceException
   */
// Path: src/main/java/javapns/communication/exceptions/InvalidKeystoreFormatException.java
// public class InvalidKeystoreFormatException extends KeystoreException {
// 
//   private static final long serialVersionUID = 8822634206752412121L;
// 
//   /**
//    * Constructor
//    */
//   public InvalidKeystoreFormatException() {
//     super("Invalid keystore format!  Make sure it is PKCS12...");
//   }
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param message
//    */
//   public InvalidKeystoreFormatException(final String message) {
//     super(message);
//   }
// 
// }
// 
// Path: src/main/java/javapns/communication/exceptions/InvalidKeystorePasswordException.java
// public class InvalidKeystorePasswordException extends KeystoreException {
// 
//   private static final long serialVersionUID = 5973743951334025887L;
// 
//   /**
//    * Constructor
//    */
//   public InvalidKeystorePasswordException() {
//     super("Invalid keystore password!  Verify settings for connecting to Apple...");
//   }
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param message
//    */
//   public InvalidKeystorePasswordException(final String message) {
//     super(message);
//   }
// 
// }
// 
// Path: src/main/java/javapns/communication/exceptions/InvalidKeystoreReferenceException.java
// public class InvalidKeystoreReferenceException extends KeystoreException {
// 
//   private static final long serialVersionUID = 3144387163593035745L;
// 
//   /**
//    * Constructor
//    */
//   public InvalidKeystoreReferenceException() {
//     super("Invalid keystore parameter.  Must be InputStream, File, String (as a file path), or byte[].");
//   }
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param keystore
//    */
//   public InvalidKeystoreReferenceException(final Object keystore) {
//     super("Invalid keystore parameter (" + keystore + ").  Must be InputStream, File, String (as a file path), or byte[].");
//   }
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param message
//    */
//   public InvalidKeystoreReferenceException(final String message) {
//     super(message);
//   }
// }
// 
// Path: src/main/java/javapns/communication/exceptions/KeystoreException.java
// public class KeystoreException extends Exception {
// 
//   private static final long serialVersionUID = 2549063865160633139L;
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param message
//    */
//   public KeystoreException(final String message) {
//     super(message);
//   }
// 
//   /**
//    * Constructor with custom message
//    *
//    * @param message
//    */
//   public KeystoreException(final String message, final Exception cause) {
//     super(message, cause);
//   }
// 
// }


// Path: src/main/java/javapns/communication/KeystoreManager.java
import javapns.communication.exceptions.InvalidKeystoreFormatException;
import javapns.communication.exceptions.InvalidKeystorePasswordException;
import javapns.communication.exceptions.InvalidKeystoreReferenceException;
import javapns.communication.exceptions.KeystoreException;
import java.io.*;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
import java.security.cert.X509Certificate;
import java.util.Enumeration;


    return password.toCharArray();
  }

  static KeystoreException wrapKeystoreException(final Exception e) {
    if (e != null) {
      final String msg = e.toString();
      if (msg.contains("javax.crypto.BadPaddingException")) {
        return new InvalidKeystorePasswordException();
      }
      if (msg.contains("DerInputStream.getLength(): lengthTag=127, too big")) {
        return new InvalidKeystoreFormatException();
      }
      if (msg.contains("java.lang.ArithmeticException: / by zero") || msg.contains("java.security.UnrecoverableKeyException: Get Key failed: / by zero")) {
        return new InvalidKeystorePasswordException("Blank passwords not supported (#38).  You must create your keystore with a non-empty password.");
      }
    }

    return new KeystoreException("Keystore exception: " + (e != null ? e.getMessage() : null), e);
  }

  /**
   * Given an object representing a keystore, returns an actual stream for that keystore.
   * Allows you to provide an actual keystore as an InputStream or a byte[] array,
   * or a reference to a keystore file as a File object or a String path.
   *
   * @param keystore a keystore containing your private key and the certificate signed by Apple (File, InputStream, byte[], KeyStore or String for a file path)
   * @return A stream to the keystore.
   * @throws InvalidKeystoreReferenceException
   */
  static InputStream streamKeystore(final Object keystore) throws InvalidKeystoreReferenceException {