• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ebourg / jsign / #419

23 Jul 2026 05:42PM UTC coverage: 81.36% (+0.08%) from 81.28%
#419

push

ebourg
Use tabs for the Gradle syntax snippets

5526 of 6792 relevant lines covered (81.36%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.21
/jsign-core/src/main/java/net/jsign/SignerHelper.java
1
/*
2
 * Copyright 2017 Emmanuel Bourg and contributors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package net.jsign;
18

19
import java.io.File;
20

21
import net.jsign.timestamp.TimestampingMode;
22

23
/**
24
 * Helper class to create AuthenticodeSigner instances with untyped parameters.
25
 * This is used internally to share the parameter validation logic
26
 * between the Ant task, the Maven/Gradle plugins and the CLI tool.
27
 *
28
 * @since 2.0
29
 */
30
class SignerHelper {
31
    public static final String PARAM_COMMAND = "command";
32
    public static final String PARAM_KEYSTORE = "keystore";
33
    public static final String PARAM_STOREPASS = "storepass";
34
    public static final String PARAM_STORETYPE = "storetype";
35
    public static final String PARAM_ALIAS = "alias";
36
    public static final String PARAM_KEYPASS = "keypass";
37
    public static final String PARAM_KEYFILE = "keyfile";
38
    public static final String PARAM_CERTFILE = "certfile";
39
    public static final String PARAM_ALG = "alg";
40
    public static final String PARAM_TSAURL = "tsaurl";
41
    public static final String PARAM_TSMODE = "tsmode";
42
    public static final String PARAM_TSRETRIES = "tsretries";
43
    public static final String PARAM_TSRETRY_WAIT = "tsretrywait";
44
    public static final String PARAM_NAME = "name";
45
    public static final String PARAM_URL = "url";
46
    public static final String PARAM_PROXY_URL = "proxyUrl";
47
    public static final String PARAM_PROXY_USER = "proxyUser";
48
    public static final String PARAM_PROXY_PASS = "proxyPass";
49
    public static final String PARAM_NON_PROXY_HOSTS = "nonProxyHosts";
50
    public static final String PARAM_REPLACE = "replace";
51
    public static final String PARAM_LAZY = "lazy";
52
    public static final String PARAM_ENCODING = "encoding";
53
    public static final String PARAM_DETACHED = "detached";
54
    public static final String PARAM_FORMAT = "format";
55
    public static final String PARAM_VALUE = "value";
56
    public static final String PARAM_VERBOSE = "verbose";
57

58
    /** The name used to refer to a configuration parameter */
59
    private final String parameterName;
60

61
    /** The command to execute */
62
    private String command = "sign";
1✔
63

64
    /** The base directory to resolve the relative paths */
65
    private File basedir;
66

67
    private String keystore;
68
    private String storepass;
69
    private String storetype;
70
    private String alias;
71
    private String keypass;
72
    private String keyfile;
73
    private String certfile;
74
    private String tsaurl;
75
    private String tsmode;
76
    private int tsretries = -1;
1✔
77
    private int tsretrywait = -1;
1✔
78
    private String alg;
79
    private String name;
80
    private String url;
81
    private final ProxySettings proxySettings = new ProxySettings();
1✔
82
    private boolean replace;
83
    private boolean lazy;
84
    private String encoding;
85
    private boolean detached;
86
    private String format;
87
    private String value;
88
    private boolean verbose;
89

90
    public SignerHelper(String parameterName) {
1✔
91
        this.parameterName = parameterName;
1✔
92
    }
1✔
93

94
    SignerHelper basedir(File basedir) {
95
        this.basedir = basedir;
1✔
96
        return this;
1✔
97
    }
98

99
    public SignerHelper command(String command) {
100
        this.command = command;
1✔
101
        return this;
1✔
102
    }
103

104
    public SignerHelper keystore(String keystore) {
105
        this.keystore = keystore;
1✔
106
        return this;
1✔
107
    }
108

109
    public SignerHelper storepass(String storepass) {
110
        this.storepass = storepass;
1✔
111
        return this;
1✔
112
    }
113

114
    public SignerHelper storetype(String storetype) {
115
        this.storetype = storetype;
1✔
116
        return this;
1✔
117
    }
118

119
    public SignerHelper alias(String alias) {
120
        this.alias = alias;
1✔
121
        return this;
1✔
122
    }
123

124
    public SignerHelper keypass(String keypass) {
125
        this.keypass = keypass;
1✔
126
        return this;
1✔
127
    }
128

129
    public SignerHelper keyfile(String keyfile) {
130
        this.keyfile = keyfile;
1✔
131
        return this;
1✔
132
    }
133

134
    public SignerHelper keyfile(File keyfile) {
135
        this.keyfile = keyfile != null ? keyfile.getAbsolutePath() : null;
1✔
136
        return this;
1✔
137
    }
138

139
    public SignerHelper certfile(String certfile) {
140
        this.certfile = certfile;
1✔
141
        return this;
1✔
142
    }
143

144
    public SignerHelper certfile(File certfile) {
145
        this.certfile = certfile != null ? certfile.getAbsolutePath() : null;
1✔
146
        return this;
1✔
147
    }
148

149
    public SignerHelper alg(String alg) {
150
        this.alg = alg;
1✔
151
        return this;
1✔
152
    }
153

154
    public SignerHelper tsaurl(String tsaurl) {
155
        this.tsaurl = tsaurl;
1✔
156
        return this;
1✔
157
    }
158

159
    public SignerHelper tsmode(String tsmode) {
160
        this.tsmode = tsmode;
1✔
161
        return this;
1✔
162
    }
163

164
    public SignerHelper tsretries(int tsretries) {
165
        this.tsretries = tsretries;
1✔
166
        return this;
1✔
167
    }
168

169
    public SignerHelper tsretrywait(int tsretrywait) {
170
        this.tsretrywait = tsretrywait;
1✔
171
        return this;
1✔
172
    }
173

174
    public SignerHelper name(String name) {
175
        this.name = name;
1✔
176
        return this;
1✔
177
    }
178

179
    public SignerHelper url(String url) {
180
        this.url = url;
1✔
181
        return this;
1✔
182
    }
183

184
    public SignerHelper proxyUrl(String proxyUrl) {
185
        this.proxySettings.url = proxyUrl;
1✔
186
        return this;
1✔
187
    }
188

189
    public SignerHelper proxyUser(String proxyUser) {
190
        this.proxySettings.username = proxyUser;
1✔
191
        return this;
1✔
192
    }
193

194
    public SignerHelper proxyPass(String proxyPass) {
195
        this.proxySettings.password = proxyPass;
1✔
196
        return this;
1✔
197
    }
198

199
    public SignerHelper nonProxyHosts(String nonProxyHosts) {
200
        this.proxySettings.nonProxyHosts = nonProxyHosts;
1✔
201
        return this;
1✔
202
    }
203

204
    public SignerHelper replace(boolean replace) {
205
        this.replace = replace;
1✔
206
        return this;
1✔
207
    }
208

209
    public SignerHelper lazy(boolean lazy) {
210
        this.lazy = lazy;
1✔
211
        return this;
1✔
212
    }
213

214
    public SignerHelper encoding(String encoding) {
215
        this.encoding = encoding;
1✔
216
        return this;
1✔
217
    }
218

219
    public SignerHelper detached(boolean detached) {
220
        this.detached = detached;
1✔
221
        return this;
1✔
222
    }
223

224
    public SignerHelper format(String format) {
225
        this.format = format;
1✔
226
        return this;
1✔
227
    }
228

229
    public SignerHelper value(String value) {
230
        this.value = value;
1✔
231
        return this;
1✔
232
    }
233

234
    public SignerHelper verbose(boolean verbose) {
235
        this.verbose = verbose;
1✔
236
        return this;
1✔
237
    }
238

239
    public SignerHelper param(String key, String value) {
240
        if (value == null) {
1✔
241
            return this;
1✔
242
        }
243
        
244
        switch (key) {
1✔
245
            case PARAM_COMMAND:    return command(value);
×
246
            case PARAM_KEYSTORE:   return keystore(value);
1✔
247
            case PARAM_STOREPASS:  return storepass(value);
1✔
248
            case PARAM_STORETYPE:  return storetype(value);
1✔
249
            case PARAM_ALIAS:      return alias(value);
1✔
250
            case PARAM_KEYPASS:    return keypass(value);
1✔
251
            case PARAM_KEYFILE:    return keyfile(value);
1✔
252
            case PARAM_CERTFILE:   return certfile(value);
1✔
253
            case PARAM_ALG:        return alg(value);
1✔
254
            case PARAM_TSAURL:     return tsaurl(value);
1✔
255
            case PARAM_TSMODE:     return tsmode(value);
1✔
256
            case PARAM_TSRETRIES:  return tsretries(Integer.parseInt(value));
1✔
257
            case PARAM_TSRETRY_WAIT: return tsretrywait(Integer.parseInt(value));
1✔
258
            case PARAM_NAME:       return name(value);
1✔
259
            case PARAM_URL:        return url(value);
1✔
260
            case PARAM_PROXY_URL:  return proxyUrl(value);
1✔
261
            case PARAM_PROXY_USER: return proxyUser(value);
1✔
262
            case PARAM_PROXY_PASS: return proxyPass(value);
1✔
263
            case PARAM_NON_PROXY_HOSTS: return nonProxyHosts(value);
1✔
264
            case PARAM_REPLACE:    return replace("true".equalsIgnoreCase(value));
×
265
            case PARAM_LAZY:       return lazy("true".equalsIgnoreCase(value));
×
266
            case PARAM_ENCODING:   return encoding(value);
1✔
267
            case PARAM_DETACHED:   return detached("true".equalsIgnoreCase(value));
×
268
            case PARAM_FORMAT:     return format(value);
×
269
            case PARAM_VALUE:      return value(value);
1✔
270
            case PARAM_VERBOSE:    return verbose("true".equalsIgnoreCase(value));
×
271
            default:
272
                throw new IllegalArgumentException("Unknown " + parameterName + ": " + key);
×
273
        }
274
    }
275

276
    public void execute(String filename) throws CommandException {
277
        File file  = new File(filename);
1✔
278
        execute(file.isAbsolute() ? file : new File(basedir, filename));
1✔
279
    }
×
280

281
    public void execute(File file) throws CommandException {
282
        switch (command) {
1✔
283
            case "sign":
284
                new JsignTool().new Sign(parameterName)
1✔
285
                        .basedir(basedir)
1✔
286
                        .keystore(keystore)
1✔
287
                        .storepass(storepass)
1✔
288
                        .storetype(storetype != null ? KeyStoreType.valueOf(storetype) : null)
1✔
289
                        .alias(alias)
1✔
290
                        .keypass(keypass)
1✔
291
                        .keyfile(keyfile)
1✔
292
                        .certfile(certfile)
1✔
293
                        .alg(alg)
1✔
294
                        .tsaurl(tsaurl)
1✔
295
                        .tsmode(tsmode != null ? TimestampingMode.of(tsmode) : null)
1✔
296
                        .tsretries(tsretries)
1✔
297
                        .tsretrywait(tsretrywait)
1✔
298
                        .name(name)
1✔
299
                        .url(url)
1✔
300
                        .proxyUrl(proxySettings.url)
1✔
301
                        .proxyUser(proxySettings.username)
1✔
302
                        .proxyPass(proxySettings.password)
1✔
303
                        .nonProxyHosts(proxySettings.nonProxyHosts)
1✔
304
                        .replace(replace)
1✔
305
                        .lazy(lazy)
1✔
306
                        .encoding(encoding)
1✔
307
                        .detached(detached)
1✔
308
                        .execute(file);
1✔
309
                break;
1✔
310

311
            case "timestamp":
312
                new JsignTool().new Timestamp<>()
1✔
313
                        .tsaurl(tsaurl)
1✔
314
                        .tsmode(tsmode != null ? TimestampingMode.of(tsmode) : null)
1✔
315
                        .tsretries(tsretries)
1✔
316
                        .tsretrywait(tsretrywait)
1✔
317
                        .proxyUrl(proxySettings.url)
1✔
318
                        .proxyUser(proxySettings.username)
1✔
319
                        .proxyPass(proxySettings.password)
1✔
320
                        .nonProxyHosts(proxySettings.nonProxyHosts)
1✔
321
                        .replace(replace)
1✔
322
                        .execute(file);
1✔
323
                break;
1✔
324

325
            case "extract":
326
                new JsignTool().new Extract().format(format).execute(file);
1✔
327
                break;
1✔
328

329
            case "remove":
330
                new JsignTool().new Remove()
1✔
331
                        .alg(alg)
1✔
332
                        .name(name)
1✔
333
                        .execute(file);
1✔
334
                break;
1✔
335

336
            case "show":
337
                new JsignTool().new Show().verbose(verbose).execute(file);
1✔
338
                break;
1✔
339

340
            case "tag":
341
                new JsignTool().new Tag().value(value).execute(file);
1✔
342
                break;
1✔
343

344
            default:
345
                throw new IllegalArgumentException("Unknown command '" + command + "'");
1✔
346
        }
347
    }
1✔
348

349
    public void sign(String file) throws CommandException {
350
        execute(file);
×
351
    }
×
352

353
    public void sign(File file) throws CommandException {
354
        execute(file);
×
355
    }
×
356
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc