Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

GpgSigner.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (C) 2018, Salesforce. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.lib;
  11. import org.eclipse.jgit.annotations.NonNull;
  12. import org.eclipse.jgit.annotations.Nullable;
  13. import org.eclipse.jgit.api.errors.CanceledException;
  14. import org.eclipse.jgit.lib.internal.BouncyCastleGpgSigner;
  15. import org.eclipse.jgit.transport.CredentialsProvider;
  16. /**
  17. * Creates GPG signatures for Git objects.
  18. *
  19. * @since 5.3
  20. */
  21. public abstract class GpgSigner {
  22. private static GpgSigner defaultSigner = new BouncyCastleGpgSigner();
  23. /**
  24. * Get the default signer, or <code>null</code>.
  25. *
  26. * @return the default signer, or <code>null</code>.
  27. */
  28. public static GpgSigner getDefault() {
  29. return defaultSigner;
  30. }
  31. /**
  32. * Set the default signer.
  33. *
  34. * @param signer
  35. * the new default signer, may be <code>null</code> to select no
  36. * default.
  37. */
  38. public static void setDefault(GpgSigner signer) {
  39. GpgSigner.defaultSigner = signer;
  40. }
  41. /**
  42. * Signs the specified commit.
  43. *
  44. * <p>
  45. * Implementors should obtain the payload for signing from the specified
  46. * commit via {@link CommitBuilder#build()} and create a proper
  47. * {@link GpgSignature}. The generated signature must be set on the
  48. * specified {@code commit} (see
  49. * {@link CommitBuilder#setGpgSignature(GpgSignature)}).
  50. * </p>
  51. * <p>
  52. * Any existing signature on the commit must be discarded prior obtaining
  53. * the payload via {@link CommitBuilder#build()}.
  54. * </p>
  55. *
  56. * @param commit
  57. * the commit to sign (must not be <code>null</code> and must be
  58. * complete to allow proper calculation of payload)
  59. * @param gpgSigningKey
  60. * the signing key to locate (passed as is to the GPG signing
  61. * tool as is; eg., value of <code>user.signingkey</code>)
  62. * @param committer
  63. * the signing identity (to help with key lookup in case signing
  64. * key is not specified)
  65. * @param credentialsProvider
  66. * provider to use when querying for signing key credentials (eg.
  67. * passphrase)
  68. * @throws CanceledException
  69. * when signing was canceled (eg., user aborted when entering
  70. * passphrase)
  71. */
  72. public abstract void sign(@NonNull CommitBuilder commit,
  73. @Nullable String gpgSigningKey, @NonNull PersonIdent committer,
  74. CredentialsProvider credentialsProvider) throws CanceledException;
  75. /**
  76. * Indicates if a signing key is available for the specified committer
  77. * and/or signing key.
  78. *
  79. * @param gpgSigningKey
  80. * the signing key to locate (passed as is to the GPG signing
  81. * tool as is; eg., value of <code>user.signingkey</code>)
  82. * @param committer
  83. * the signing identity (to help with key lookup in case signing
  84. * key is not specified)
  85. * @param credentialsProvider
  86. * provider to use when querying for signing key credentials (eg.
  87. * passphrase)
  88. * @return <code>true</code> if a signing key is available,
  89. * <code>false</code> otherwise
  90. * @throws CanceledException
  91. * when signing was canceled (eg., user aborted when entering
  92. * passphrase)
  93. */
  94. public abstract boolean canLocateSigningKey(@Nullable String gpgSigningKey,
  95. @NonNull PersonIdent committer,
  96. CredentialsProvider credentialsProvider) throws CanceledException;
  97. }