// Path: lib/src/main/java/com/google/capillary/Config.java
// public final class Config {
// 
//   /**
//    * Initializes the Capillary library.
//    *
//    * <p>This should be called before using any functionality provided by Capillary.
//    *
//    * @throws GeneralSecurityException if the initialization fails.
//    */
//   public static void initialize() throws GeneralSecurityException {
//     com.google.crypto.tink.Config.register(SignatureConfig.TINK_1_1_0);
//     com.google.crypto.tink.Config.register(AeadConfig.TINK_1_1_0);
//   }
// }
// 
// Path: lib/src/main/java/com/google/capillary/RsaEcdsaEncrypterManager.java
// public final class RsaEcdsaEncrypterManager extends EncrypterManager {
// 
//   private final PublicKeySign senderSigner;
// 
//   /**
//    * Constructs a new RSA-ECDSA EncrypterManager.
//    *
//    * <p>Please note that the {@link InputStream} {@code senderSigningKey} will not be closed.
//    *
//    * @param senderSigningKey the serialized Tink signing key.
//    * @throws GeneralSecurityException if the initialization fails.
//    * @throws IOException if the given sender signing key cannot be read.
//    */
//   public RsaEcdsaEncrypterManager(InputStream senderSigningKey)
//       throws GeneralSecurityException, IOException {
//     KeysetHandle signingKeyHandle = CleartextKeysetHandle
//         .read(BinaryKeysetReader.withInputStream(senderSigningKey));
//     senderSigner = PublicKeySignFactory.getPrimitive(signingKeyHandle);
//   }
// 
//   @Override
//   HybridEncrypt rawLoadPublicKey(byte[] publicKey) throws GeneralSecurityException {
//     WrappedRsaEcdsaPublicKey wrappedRsaEcdsaPublicKey;
//     try {
//       wrappedRsaEcdsaPublicKey = WrappedRsaEcdsaPublicKey.parseFrom(publicKey);
//     } catch (InvalidProtocolBufferException e) {
//       throw new GeneralSecurityException("unable to parse public key", e);
//     }
//     PublicKey recipientPublicKey = KeyFactory.getInstance("RSA").generatePublic(
//         new X509EncodedKeySpec(wrappedRsaEcdsaPublicKey.getKeyBytes().toByteArray()));
//     return new RsaEcdsaHybridEncrypt.Builder()
//         .withSenderSigner(senderSigner)
//         .withRecipientPublicKey(recipientPublicKey)
//         .withPadding(RsaEcdsaConstants.Padding.valueOf(wrappedRsaEcdsaPublicKey.getPadding()))
//         .build();
//   }
// }
// 
// Path: lib/src/main/java/com/google/capillary/WebPushEncrypterManager.java
// public final class WebPushEncrypterManager extends EncrypterManager {
// 
//   @Override
//   HybridEncrypt rawLoadPublicKey(byte[] publicKey) throws GeneralSecurityException {
//     WrappedWebPushPublicKey wrappedWebPushPublicKey;
//     try {
//       wrappedWebPushPublicKey = WrappedWebPushPublicKey.parseFrom(publicKey);
//     } catch (InvalidProtocolBufferException e) {
//       throw new GeneralSecurityException("unable to parse public key", e);
//     }
//     return new WebPushHybridEncrypt.Builder()
//         .withAuthSecret(wrappedWebPushPublicKey.getAuthSecret().toByteArray())
//         .withRecipientPublicKey(wrappedWebPushPublicKey.getKeyBytes().toByteArray())
//         .build();
//   }
// }


import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import com.google.capillary.Config;
import com.google.capillary.RsaEcdsaEncrypterManager;
import com.google.capillary.WebPushEncrypterManager;
import io.grpc.BindableService;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.sql.SQLException;
import java.util.logging.Logger;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
/*
 * Copyright 2018 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.capillary.demo.server;


/**
 * The starting point of the demo app server.
 */
public final class DemoServer {

  private static final Logger logger = Logger.getLogger(DemoServer.class.getName());
  private static final String PORT_OPTION = "port";
  private static final String DATABASE_PATH_OPTION = "database_path";
  private static final String ECDSA_PRIVATE_KEY_PATH_OPTION = "ecdsa_private_key_path";
  private static final String TLS_CERT_PATH_OPTION = "tls_cert_path";
  private static final String TLS_PRIVATE_KEY_PATH_OPTION = "tls_private_key_path";
  private static final String SERVICE_ACCOUNT_CREDENTIALS_PATH_OPTION =
      "service_account_credentials_path";
  private static final String FIREBASE_PROJECT_ID_OPTION = "firebase_project_id";

  private Server server;

  /**
   * Launches the server.
   *
   * @param args the command line args.
   * @throws Exception as a catch-all exception in main method.
   */
  public static void main(String[] args) throws Exception {
    // Initialize the Capillary library.
// Path: lib/src/main/java/com/google/capillary/Config.java
// public final class Config {
// 
//   /**
//    * Initializes the Capillary library.
//    *
//    * <p>This should be called before using any functionality provided by Capillary.
//    *
//    * @throws GeneralSecurityException if the initialization fails.
//    */
//   public static void initialize() throws GeneralSecurityException {
//     com.google.crypto.tink.Config.register(SignatureConfig.TINK_1_1_0);
//     com.google.crypto.tink.Config.register(AeadConfig.TINK_1_1_0);
//   }
// }
// 
// Path: lib/src/main/java/com/google/capillary/RsaEcdsaEncrypterManager.java
// public final class RsaEcdsaEncrypterManager extends EncrypterManager {
// 
//   private final PublicKeySign senderSigner;
// 
//   /**
//    * Constructs a new RSA-ECDSA EncrypterManager.
//    *
//    * <p>Please note that the {@link InputStream} {@code senderSigningKey} will not be closed.
//    *
//    * @param senderSigningKey the serialized Tink signing key.
//    * @throws GeneralSecurityException if the initialization fails.
//    * @throws IOException if the given sender signing key cannot be read.
//    */
//   public RsaEcdsaEncrypterManager(InputStream senderSigningKey)
//       throws GeneralSecurityException, IOException {
//     KeysetHandle signingKeyHandle = CleartextKeysetHandle
//         .read(BinaryKeysetReader.withInputStream(senderSigningKey));
//     senderSigner = PublicKeySignFactory.getPrimitive(signingKeyHandle);
//   }
// 
//   @Override
//   HybridEncrypt rawLoadPublicKey(byte[] publicKey) throws GeneralSecurityException {
//     WrappedRsaEcdsaPublicKey wrappedRsaEcdsaPublicKey;
//     try {
//       wrappedRsaEcdsaPublicKey = WrappedRsaEcdsaPublicKey.parseFrom(publicKey);
//     } catch (InvalidProtocolBufferException e) {
//       throw new GeneralSecurityException("unable to parse public key", e);
//     }
//     PublicKey recipientPublicKey = KeyFactory.getInstance("RSA").generatePublic(
//         new X509EncodedKeySpec(wrappedRsaEcdsaPublicKey.getKeyBytes().toByteArray()));
//     return new RsaEcdsaHybridEncrypt.Builder()
//         .withSenderSigner(senderSigner)
//         .withRecipientPublicKey(recipientPublicKey)
//         .withPadding(RsaEcdsaConstants.Padding.valueOf(wrappedRsaEcdsaPublicKey.getPadding()))
//         .build();
//   }
// }
// 
// Path: lib/src/main/java/com/google/capillary/WebPushEncrypterManager.java
// public final class WebPushEncrypterManager extends EncrypterManager {
// 
//   @Override
//   HybridEncrypt rawLoadPublicKey(byte[] publicKey) throws GeneralSecurityException {
//     WrappedWebPushPublicKey wrappedWebPushPublicKey;
//     try {
//       wrappedWebPushPublicKey = WrappedWebPushPublicKey.parseFrom(publicKey);
//     } catch (InvalidProtocolBufferException e) {
//       throw new GeneralSecurityException("unable to parse public key", e);
//     }
//     return new WebPushHybridEncrypt.Builder()
//         .withAuthSecret(wrappedWebPushPublicKey.getAuthSecret().toByteArray())
//         .withRecipientPublicKey(wrappedWebPushPublicKey.getKeyBytes().toByteArray())
//         .build();
//   }
// }


// Path: demo/server/src/main/java/com/google/capillary/demo/server/DemoServer.java
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import com.google.capillary.Config;
import com.google.capillary.RsaEcdsaEncrypterManager;
import com.google.capillary.WebPushEncrypterManager;
import io.grpc.BindableService;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.sql.SQLException;
import java.util.logging.Logger;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;

/*
 * Copyright 2018 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.capillary.demo.server;


/**
 * The starting point of the demo app server.
 */
public final class DemoServer {

  private static final Logger logger = Logger.getLogger(DemoServer.class.getName());
  private static final String PORT_OPTION = "port";
  private static final String DATABASE_PATH_OPTION = "database_path";
  private static final String ECDSA_PRIVATE_KEY_PATH_OPTION = "ecdsa_private_key_path";
  private static final String TLS_CERT_PATH_OPTION = "tls_cert_path";
  private static final String TLS_PRIVATE_KEY_PATH_OPTION = "tls_private_key_path";
  private static final String SERVICE_ACCOUNT_CREDENTIALS_PATH_OPTION =
      "service_account_credentials_path";
  private static final String FIREBASE_PROJECT_ID_OPTION = "firebase_project_id";

  private Server server;

  /**
   * Launches the server.
   *
   * @param args the command line args.
   * @throws Exception as a catch-all exception in main method.
   */
  public static void main(String[] args) throws Exception {
    // Initialize the Capillary library.
    Config.initialize();