1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.util;
11
12 import java.text.MessageFormat;
13 import java.util.Locale;
14
15 import org.eclipse.jgit.internal.JGitText;
16 import org.eclipse.jgit.lib.GpgSignatureVerifier.SignatureVerification;
17 import org.eclipse.jgit.lib.GpgSignatureVerifier.TrustLevel;
18 import org.eclipse.jgit.lib.PersonIdent;
19
20
21
22
23
24
25 public final class SignatureUtils {
26
27 private SignatureUtils() {
28
29 }
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public static String toString(SignatureVerification verification,
44 PersonIdent creator, GitDateFormatter formatter) {
45 StringBuilder result = new StringBuilder();
46
47 PersonIdent dateId = new PersonIdent(creator,
48 verification.getCreationDate());
49 result.append(MessageFormat.format(JGitText.get().verifySignatureMade,
50 formatter.formatDate(dateId)));
51 result.append('\n');
52 result.append(MessageFormat.format(
53 JGitText.get().verifySignatureKey,
54 verification.getKeyFingerprint().toUpperCase(Locale.ROOT)));
55 result.append('\n');
56 if (!StringUtils.isEmptyOrNull(verification.getSigner())) {
57 result.append(
58 MessageFormat.format(JGitText.get().verifySignatureIssuer,
59 verification.getSigner()));
60 result.append('\n');
61 }
62 String msg;
63 if (verification.getVerified()) {
64 if (verification.isExpired()) {
65 msg = JGitText.get().verifySignatureExpired;
66 } else {
67 msg = JGitText.get().verifySignatureGood;
68 }
69 } else {
70 msg = JGitText.get().verifySignatureBad;
71 }
72 result.append(MessageFormat.format(msg, verification.getKeyUser()));
73 if (!TrustLevel.UNKNOWN.equals(verification.getTrustLevel())) {
74 result.append(' ' + MessageFormat
75 .format(JGitText.get().verifySignatureTrust, verification
76 .getTrustLevel().name().toLowerCase(Locale.ROOT)));
77 }
78 result.append('\n');
79 msg = verification.getMessage();
80 if (!StringUtils.isEmptyOrNull(msg)) {
81 result.append(msg);
82 result.append('\n');
83 }
84 return result.toString();
85 }
86 }