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

ebourg / jsign / #422

04 Aug 2026 09:03AM UTC coverage: 81.859% (+0.5%) from 81.393%
#422

push

ebourg
Marked the Jsign 8.0 preview features in the documentation

6200 of 7574 relevant lines covered (81.86%)

0.82 hits per line

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

90.74
/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
import java.util.stream.Stream;
21
import java.time.LocalDate;
22

23
import net.jsign.timestamp.TimestampingMode;
24

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

61
    /** The name used to refer to a configuration parameter */
62
    private final String parameterName;
63

64
    /** The command to execute */
65
    private String command = "sign";
1✔
66

67
    /** The base directory to resolve the relative paths */
68
    private File basedir;
69

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

94
    public SignerHelper(String parameterName) {
1✔
95
        this.parameterName = parameterName;
1✔
96
    }
1✔
97

98
    SignerHelper basedir(File basedir) {
99
        this.basedir = basedir;
1✔
100
        return this;
1✔
101
    }
102

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

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

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

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

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

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

133
    public SignerHelper keyfile(String keyfile) {
134
        this.keyfile = keyfile;
1✔
135
        return this;
1✔
136
    }
137

138
    public SignerHelper keyfile(File keyfile) {
139
        this.keyfile = keyfile != null ? keyfile.getAbsolutePath() : null;
1✔
140
        return this;
1✔
141
    }
142

143
    public SignerHelper certfile(String certfile) {
144
        this.certfile = certfile;
1✔
145
        return this;
1✔
146
    }
147

148
    public SignerHelper certfile(File certfile) {
149
        this.certfile = certfile != null ? certfile.getAbsolutePath() : null;
1✔
150
        return this;
1✔
151
    }
152

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

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

163
    public SignerHelper tsmode(String tsmode) {
164
        this.tsmode = tsmode;
1✔
165
        return this;
1✔
166
    }
167

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

173
    public SignerHelper tsretrywait(int tsretrywait) {
174
        this.tsretrywait = tsretrywait;
1✔
175
        return this;
1✔
176
    }
177

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

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

188
    public SignerHelper proxyUrl(String proxyUrl) {
189
        this.proxySettings.url = proxyUrl;
1✔
190
        return this;
1✔
191
    }
192

193
    public SignerHelper proxyUser(String proxyUser) {
194
        this.proxySettings.username = proxyUser;
1✔
195
        return this;
1✔
196
    }
197

198
    public SignerHelper proxyPass(String proxyPass) {
199
        this.proxySettings.password = proxyPass;
1✔
200
        return this;
1✔
201
    }
202

203
    public SignerHelper nonProxyHosts(String nonProxyHosts) {
204
        this.proxySettings.nonProxyHosts = nonProxyHosts;
1✔
205
        return this;
1✔
206
    }
207

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

213
    public SignerHelper lazy(boolean lazy) {
214
        this.lazy = lazy;
1✔
215
        return this;
1✔
216
    }
217

218
    public SignerHelper encoding(String encoding) {
219
        this.encoding = encoding;
1✔
220
        return this;
1✔
221
    }
222

223
    public SignerHelper detached(boolean detached) {
224
        this.detached = detached;
1✔
225
        return this;
1✔
226
    }
227

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

233
    public SignerHelper value(String value) {
234
        this.value = value;
1✔
235
        return this;
1✔
236
    }
237

238
    public SignerHelper verbose(boolean verbose) {
239
        this.verbose = verbose;
1✔
240
        return this;
1✔
241
    }
242

243
    public SignerHelper date(String date) {
244
        this.date = date;
×
245
        return this;
×
246
    }
247

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

286
    public void execute(String filename) throws CommandException {
287
        File file  = new File(filename);
1✔
288
        execute(file.isAbsolute() ? file : new File(basedir, filename));
1✔
289
    }
×
290

291
    public void execute(File file) throws CommandException {
292
        getCommand().execute(file);
1✔
293
    }
1✔
294

295
    public void execute(Stream<File> files) throws CommandException {
296
        getCommand().execute(files);
1✔
297
    }
1✔
298

299
    private JsignTool.Command<?> getCommand() {
300
        switch (command) {
1✔
301
            case "sign":
302
                return new JsignTool().new Sign(parameterName)
1✔
303
                        .basedir(basedir)
1✔
304
                        .keystore(keystore)
1✔
305
                        .storepass(storepass)
1✔
306
                        .storetype(storetype != null ? KeyStoreType.valueOf(storetype) : null)
1✔
307
                        .alias(alias)
1✔
308
                        .keypass(keypass)
1✔
309
                        .keyfile(keyfile)
1✔
310
                        .certfile(certfile)
1✔
311
                        .alg(alg)
1✔
312
                        .tsaurl(tsaurl)
1✔
313
                        .tsmode(tsmode != null ? TimestampingMode.of(tsmode) : null)
1✔
314
                        .tsretries(tsretries)
1✔
315
                        .tsretrywait(tsretrywait)
1✔
316
                        .name(name)
1✔
317
                        .url(url)
1✔
318
                        .proxyUrl(proxySettings.url)
1✔
319
                        .proxyUser(proxySettings.username)
1✔
320
                        .proxyPass(proxySettings.password)
1✔
321
                        .nonProxyHosts(proxySettings.nonProxyHosts)
1✔
322
                        .replace(replace)
1✔
323
                        .lazy(lazy)
1✔
324
                        .encoding(encoding)
1✔
325
                        .detached(detached);
1✔
326

327
            case "timestamp":
328
                return new JsignTool().new Timestamp<>()
1✔
329
                        .tsaurl(tsaurl)
1✔
330
                        .tsmode(tsmode != null ? TimestampingMode.of(tsmode) : null)
1✔
331
                        .tsretries(tsretries)
1✔
332
                        .tsretrywait(tsretrywait)
1✔
333
                        .proxyUrl(proxySettings.url)
1✔
334
                        .proxyUser(proxySettings.username)
1✔
335
                        .proxyPass(proxySettings.password)
1✔
336
                        .nonProxyHosts(proxySettings.nonProxyHosts)
1✔
337
                        .replace(replace);
1✔
338

339
            case "extract":
340
                return new JsignTool().new Extract().format(format);
1✔
341

342
            case "remove":
343
                return new JsignTool().new Remove()
1✔
344
                        .alg(alg)
1✔
345
                        .name(name);
1✔
346

347
            case "show":
348
                return new JsignTool().new Show().verbose(verbose);
1✔
349

350
            case "tag":
351
                return new JsignTool().new Tag().value(value);
1✔
352

353
            case "verify":
354
                return new JsignTool().new Verify()
1✔
355
                        .basedir(basedir)
1✔
356
                        .date(date != null ? LocalDate.parse(date) : null)
1✔
357
                        .certfile(certfile)
1✔
358
                        .lazy(lazy)
1✔
359
                        .encoding(encoding)
1✔
360
                        .proxyUrl(proxySettings.url)
1✔
361
                        .proxyUser(proxySettings.username)
1✔
362
                        .proxyPass(proxySettings.password)
1✔
363
                        .nonProxyHosts(proxySettings.nonProxyHosts)
1✔
364
                        .verbose(verbose);
1✔
365

366
            default:
367
                throw new IllegalArgumentException("Unknown command '" + command + "'");
1✔
368
        }
369
    }
370

371
    public void sign(String file) throws CommandException {
372
        execute(file);
×
373
    }
×
374

375
    public void sign(File file) throws CommandException {
376
        execute(file);
×
377
    }
×
378
}
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