// Path: lib/src/main/java/com/google/capillary/AuthModeUnavailableException.java
// public final class AuthModeUnavailableException extends CapillaryException {
// 
//   /**
//    * Creates a new {@link AuthModeUnavailableException} instance.
//    *
//    * @param msg the exception message.
//    */
//   public AuthModeUnavailableException(String msg) {
//     super(msg);
//   }
// }
// 
// Path: lib/src/main/java/com/google/capillary/NoSuchKeyException.java
// public final class NoSuchKeyException extends CapillaryException {
// 
//   /**
//    * Creates a new {@link NoSuchKeyException} object.
//    *
//    * @param msg the exception message.
//    */
//   public NoSuchKeyException(String msg) {
//     super(msg);
//   }
// }


import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.VisibleForTesting;
import com.google.capillary.AuthModeUnavailableException;
import com.google.capillary.NoSuchKeyException;
import com.google.capillary.internal.CapillaryPublicKey;
import com.google.crypto.tink.HybridDecrypt;
import com.google.protobuf.ByteString;
import java.security.GeneralSecurityException;
import java.util.UUID;
    if (currentSerialNumber == -1) {
      throw new NoSuchKeyException(toKeyTypeString(isAuth) + " key not initialized");
    }
    return currentSerialNumber;
  }

  /**
   * Generates a raw key pair underlying a Capillary key pair.
   *
   * <p>The private key of the generated key pair should ideally be stored in the Android Keystore,
   * which attempts to bind the private keys to a secure hardware on the device.
   */
  abstract void rawGenerateKeyPair(boolean isAuth) throws GeneralSecurityException;

  /**
   * Provides a Capillary public key.
   *
   * <p>The key must have been generated using {@code generateKey}. The key will be returned via
   * the provided Capillary handler.
   *
   * @param isAuth whether the user must authenticate (i.e., by unlocking the device) before the
   *     generated key could be used.
   * @param handler the Capillary handler instance.
   * @param extra the extra parameters to be passed back to the provided handler.
   * @throws NoSuchKeyException if the requested key does not exist.
   * @throws AuthModeUnavailableException if an authenticated key was requested but the user has not
   *     enabled authentication (i.e., a device with no screen lock).
   * @throws GeneralSecurityException if the public key could not be retrieved.
   */
  public void getPublicKey(boolean isAuth, CapillaryHandler handler, Object extra)
// Path: lib/src/main/java/com/google/capillary/AuthModeUnavailableException.java
// public final class AuthModeUnavailableException extends CapillaryException {
// 
//   /**
//    * Creates a new {@link AuthModeUnavailableException} instance.
//    *
//    * @param msg the exception message.
//    */
//   public AuthModeUnavailableException(String msg) {
//     super(msg);
//   }
// }
// 
// Path: lib/src/main/java/com/google/capillary/NoSuchKeyException.java
// public final class NoSuchKeyException extends CapillaryException {
// 
//   /**
//    * Creates a new {@link NoSuchKeyException} object.
//    *
//    * @param msg the exception message.
//    */
//   public NoSuchKeyException(String msg) {
//     super(msg);
//   }
// }


// Path: lib-android/src/main/java/com/google/capillary/android/KeyManager.java
import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.VisibleForTesting;
import com.google.capillary.AuthModeUnavailableException;
import com.google.capillary.NoSuchKeyException;
import com.google.capillary.internal.CapillaryPublicKey;
import com.google.crypto.tink.HybridDecrypt;
import com.google.protobuf.ByteString;
import java.security.GeneralSecurityException;
import java.util.UUID;

    if (currentSerialNumber == -1) {
      throw new NoSuchKeyException(toKeyTypeString(isAuth) + " key not initialized");
    }
    return currentSerialNumber;
  }

  /**
   * Generates a raw key pair underlying a Capillary key pair.
   *
   * <p>The private key of the generated key pair should ideally be stored in the Android Keystore,
   * which attempts to bind the private keys to a secure hardware on the device.
   */
  abstract void rawGenerateKeyPair(boolean isAuth) throws GeneralSecurityException;

  /**
   * Provides a Capillary public key.
   *
   * <p>The key must have been generated using {@code generateKey}. The key will be returned via
   * the provided Capillary handler.
   *
   * @param isAuth whether the user must authenticate (i.e., by unlocking the device) before the
   *     generated key could be used.
   * @param handler the Capillary handler instance.
   * @param extra the extra parameters to be passed back to the provided handler.
   * @throws NoSuchKeyException if the requested key does not exist.
   * @throws AuthModeUnavailableException if an authenticated key was requested but the user has not
   *     enabled authentication (i.e., a device with no screen lock).
   * @throws GeneralSecurityException if the public key could not be retrieved.
   */
  public void getPublicKey(boolean isAuth, CapillaryHandler handler, Object extra)
      throws NoSuchKeyException, AuthModeUnavailableException, GeneralSecurityException {