Class GpgSigner

  • Direct Known Subclasses:
    BouncyCastleGpgSigner

    public abstract class GpgSigner
    extends Object
    Creates GPG signatures for Git objects.
    Since:
    5.3
    • Constructor Detail

      • GpgSigner

        public GpgSigner()
    • Method Detail

      • getDefault

        public static GpgSigner getDefault()
        Get the default signer, or null.
        Returns:
        the default signer, or null.
      • setDefault

        public static void setDefault​(GpgSigner signer)
        Set the default signer.
        Parameters:
        signer - the new default signer, may be null to select no default.
      • sign

        public abstract void sign​(@NonNull
                                  CommitBuilder commit,
                                  @Nullable
                                  String gpgSigningKey,
                                  @NonNull
                                  PersonIdent committer,
                                  CredentialsProvider credentialsProvider)
                           throws CanceledException
        Signs the specified commit.

        Implementors should obtain the payload for signing from the specified commit via CommitBuilder.build() and create a proper GpgSignature. The generated signature must be set on the specified commit (see ObjectBuilder.setGpgSignature(GpgSignature)).

        Any existing signature on the commit must be discarded prior obtaining the payload via CommitBuilder.build().

        Parameters:
        commit - the commit to sign (must not be null and must be complete to allow proper calculation of payload)
        gpgSigningKey - the signing key to locate (passed as is to the GPG signing tool as is; eg., value of user.signingkey)
        committer - the signing identity (to help with key lookup in case signing key is not specified)
        credentialsProvider - provider to use when querying for signing key credentials (eg. passphrase)
        Throws:
        CanceledException - when signing was canceled (eg., user aborted when entering passphrase)
      • canLocateSigningKey

        public abstract boolean canLocateSigningKey​(@Nullable
                                                    String gpgSigningKey,
                                                    @NonNull
                                                    PersonIdent committer,
                                                    CredentialsProvider credentialsProvider)
                                             throws CanceledException
        Indicates if a signing key is available for the specified committer and/or signing key.
        Parameters:
        gpgSigningKey - the signing key to locate (passed as is to the GPG signing tool as is; eg., value of user.signingkey)
        committer - the signing identity (to help with key lookup in case signing key is not specified)
        credentialsProvider - provider to use when querying for signing key credentials (eg. passphrase)
        Returns:
        true if a signing key is available, false otherwise
        Throws:
        CanceledException - when signing was canceled (eg., user aborted when entering passphrase)