You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VerificationUtils.java 1.6KB

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