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.

GpgConfig.java 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) 2018, Salesforce. 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. /**
  12. * Typed access to GPG related configuration options.
  13. *
  14. * @since 5.2
  15. */
  16. public class GpgConfig {
  17. /**
  18. * Config values for gpg.format.
  19. */
  20. public enum GpgFormat implements Config.ConfigEnum {
  21. /** Value for openpgp */
  22. OPENPGP("openpgp"), //$NON-NLS-1$
  23. /** Value for x509 */
  24. X509("x509"); //$NON-NLS-1$
  25. private final String configValue;
  26. private GpgFormat(String configValue) {
  27. this.configValue = configValue;
  28. }
  29. @Override
  30. public boolean matchConfigValue(String s) {
  31. return configValue.equals(s);
  32. }
  33. @Override
  34. public String toConfigValue() {
  35. return configValue;
  36. }
  37. }
  38. private final Config config;
  39. /**
  40. * Create a new GPG config, which will read configuration from config.
  41. *
  42. * @param config
  43. * the config to read from
  44. */
  45. public GpgConfig(Config config) {
  46. this.config = config;
  47. }
  48. /**
  49. * Retrieves the config value of gpg.format.
  50. *
  51. * @return the {@link org.eclipse.jgit.lib.GpgConfig.GpgFormat}
  52. */
  53. public GpgFormat getKeyFormat() {
  54. return config.getEnum(GpgFormat.values(),
  55. ConfigConstants.CONFIG_GPG_SECTION, null,
  56. ConfigConstants.CONFIG_KEY_FORMAT, GpgFormat.OPENPGP);
  57. }
  58. /**
  59. * Retrieves the config value of user.signingKey.
  60. *
  61. * @return the value of user.signingKey (may be <code>null</code>)
  62. */
  63. public String getSigningKey() {
  64. return config.getString(ConfigConstants.CONFIG_USER_SECTION, null,
  65. ConfigConstants.CONFIG_KEY_SIGNINGKEY);
  66. }
  67. /**
  68. * Retrieves the config value of commit.gpgSign.
  69. *
  70. * @return the value of commit.gpgSign (defaults to <code>false</code>)
  71. */
  72. public boolean isSignCommits() {
  73. return config.getBoolean(ConfigConstants.CONFIG_COMMIT_SECTION,
  74. ConfigConstants.CONFIG_KEY_GPGSIGN, false);
  75. }
  76. }