private[tasks] def doSignPlugin()

in ideaSupport/src/main/scala/org/jetbrains/sbtidea/tasks/SignPluginArtifactTask.scala [28:53]


  private[tasks] def doSignPlugin(opts: PluginSigningOptions, inputFile: File, outputFile: File): File = {
    def sign(certs: util.List[X509Certificate], key: PrivateKey): File = {
      val signatureProvider = new DefaultSignatureProvider(
        PublicKeyUtils.INSTANCE.getSuggestedSignatureAlgorithm(certs.get(0).getPublicKey),
        key)
      ZipSigner.sign(inputFile, outputFile, certs, signatureProvider)
      outputFile
    }
    opts match {
      case PluginSigningOptions(true, Some(certFile), Some(privateKeyFile), Some(keyPassphrase)) =>
        val info = SignerInfoLoader.INSTANCE.loadSignerInfoFromFiles(privateKeyFile, certFile, keyPassphrase.toCharArray)
        sign(info.component1(), info.component2())
      case PluginSigningOptions(true, Some(certFile), Some(privateKeyFile), None) =>
        val info = SignerInfoLoader.INSTANCE.loadSignerInfoFromFiles(privateKeyFile, certFile)
        sign(info.component1(), info.component2())
      case PluginSigningOptions(true, None, Some(_), _) =>
        throw new IllegalArgumentException("Certificate chain file doesn't exist")
      case PluginSigningOptions(true, Some(_), None, _) =>
        throw new IllegalArgumentException("Private key file doesn't exist")
      case PluginSigningOptions(false, _, _, _) =>
        throw new IllegalStateException("Plugin signing disabled in options")
      case other =>
        throw new IllegalStateException(s"Unsupported plugin signing: $other")
    }

  }