aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
diff options
context:
space:
mode:
authorDavid Turner <dturner@twosigma.com>2018-06-14 20:05:38 -0400
committerMatthias Sohn <matthias.sohn@sap.com>2018-09-04 20:13:16 +0200
commit559c68cb012b971bf506d12aaf0a0f0504c9780b (patch)
treee3e8b5e4f7b6a4e8b3c70c8e583917d12e474201 /org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
parent30c6c7542190c149e2aee792f992a312a5fc5793 (diff)
downloadjgit-559c68cb012b971bf506d12aaf0a0f0504c9780b.tar.gz
jgit-559c68cb012b971bf506d12aaf0a0f0504c9780b.zip
Parse signature of GPG-signed commits
In order to support GPG-signed commits, add some methods which will allow GPG signatures to be parsed out of RevCommit objects. Later, we can add code to verify the signatures. Change-Id: Ifcf6b3ac79115c15d3ec4b4eaed07315534d09ac Signed-off-by: David Turner <dturner@twosigma.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
index 5bd5dd6368..86ecd8eaee 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
@@ -51,6 +51,7 @@ import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -390,6 +391,34 @@ public class RevCommit extends RevObject {
}
/**
+ * Parse the gpg signature from the raw buffer.
+ * <p>
+ * This method parses and returns the raw content of the gpgsig lines. This
+ * method is fairly expensive and produces a new byte[] instance on each
+ * invocation. Callers should invoke this method only if they are certain
+ * they will need, and should cache the return value for as long as
+ * necessary to use all information from it.
+ * <p>
+ * RevFilter implementations should try to use
+ * {@link org.eclipse.jgit.util.RawParseUtils} to scan the
+ * {@link #getRawBuffer()} instead, as this will allow faster evaluation of
+ * commits.
+ *
+ * @return contents of the gpg signature; null if the commit was not signed.
+ * @since 5.1
+ */
+ public final @Nullable byte[] getRawGpgSignature() {
+ final byte[] raw = buffer;
+ final byte[] header = {'g', 'p', 'g', 's', 'i', 'g'};
+ final int start = RawParseUtils.headerStart(header, raw, 0);
+ if (start < 0) {
+ return null;
+ }
+ final int end = RawParseUtils.headerEnd(raw, start);
+ return Arrays.copyOfRange(raw, start, end);
+ }
+
+ /**
* Parse the author identity from the raw buffer.
* <p>
* This method parses and returns the content of the author line, after