View Javadoc
1   /*
2    * Copyright (C) 2021, Thomas Wolf <thomas.wolf@paranor.ch> 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.pgm.internal;
11  
12  import java.io.IOException;
13  
14  import org.eclipse.jgit.lib.GpgSignatureVerifier.SignatureVerification;
15  import org.eclipse.jgit.lib.PersonIdent;
16  import org.eclipse.jgit.util.GitDateFormatter;
17  import org.eclipse.jgit.util.SignatureUtils;
18  import org.eclipse.jgit.util.io.ThrowingPrintWriter;
19  
20  /**
21   * Utilities for signature verification.
22   */
23  public final class VerificationUtils {
24  
25  	private VerificationUtils() {
26  		// No instantiation
27  	}
28  
29  	/**
30  	 * Writes information about a signature verification to the given writer.
31  	 *
32  	 * @param out
33  	 *            to write to
34  	 * @param verification
35  	 *            to show
36  	 * @param name
37  	 *            of the verifier used
38  	 * @param creator
39  	 *            of the object verified; used for time zone information
40  	 * @throws IOException
41  	 *             if writing fails
42  	 */
43  	public static void writeVerification(ThrowingPrintWriter out,
44  			SignatureVerification verification, String name,
45  			PersonIdent creator) throws IOException {
46  		String[] text = SignatureUtils
47  				.toString(verification, creator,
48  						new GitDateFormatter(GitDateFormatter.Format.LOCALE))
49  				.split("\n"); //$NON-NLS-1$
50  		for (String line : text) {
51  			out.print(name);
52  			out.print(": "); //$NON-NLS-1$
53  			out.println(line);
54  		}
55  	}
56  }