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.

GpgSignatureVerifierFactory.java 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.lib;
  11. import java.util.Iterator;
  12. import java.util.ServiceConfigurationError;
  13. import java.util.ServiceLoader;
  14. import org.slf4j.Logger;
  15. import org.slf4j.LoggerFactory;
  16. /**
  17. * A {@code GpgSignatureVerifierFactory} creates {@link GpgSignatureVerifier} instances.
  18. *
  19. * @since 5.11
  20. */
  21. public abstract class GpgSignatureVerifierFactory {
  22. private static final Logger LOG = LoggerFactory
  23. .getLogger(GpgSignatureVerifierFactory.class);
  24. private static volatile GpgSignatureVerifierFactory defaultFactory = loadDefault();
  25. private static GpgSignatureVerifierFactory loadDefault() {
  26. try {
  27. ServiceLoader<GpgSignatureVerifierFactory> loader = ServiceLoader
  28. .load(GpgSignatureVerifierFactory.class);
  29. Iterator<GpgSignatureVerifierFactory> iter = loader.iterator();
  30. if (iter.hasNext()) {
  31. return iter.next();
  32. }
  33. } catch (ServiceConfigurationError e) {
  34. LOG.error(e.getMessage(), e);
  35. }
  36. return null;
  37. }
  38. /**
  39. * Retrieves the default factory.
  40. *
  41. * @return the default factory or {@code null} if none set
  42. */
  43. public static GpgSignatureVerifierFactory getDefault() {
  44. return defaultFactory;
  45. }
  46. /**
  47. * Sets the default factory.
  48. *
  49. * @param factory
  50. * the new default factory
  51. */
  52. public static void setDefault(GpgSignatureVerifierFactory factory) {
  53. defaultFactory = factory;
  54. }
  55. /**
  56. * Creates a new {@link GpgSignatureVerifier}.
  57. *
  58. * @return the new {@link GpgSignatureVerifier}
  59. */
  60. public abstract GpgSignatureVerifier getVerifier();
  61. }