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