1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.netty.handler.ssl.util;
18
19 import static io.netty.util.internal.ObjectUtil.checkNotNull;
20 import static io.netty.util.internal.ObjectUtil.checkNotNullWithIAE;
21
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.List;
25
26
27
28
29 public final class FingerprintTrustManagerFactoryBuilder {
30
31
32
33
34 private final String algorithm;
35
36
37
38
39 private final List<String> fingerprints = new ArrayList<String>();
40
41
42
43
44
45
46 FingerprintTrustManagerFactoryBuilder(String algorithm) {
47 this.algorithm = checkNotNull(algorithm, "algorithm");
48 }
49
50
51
52
53
54
55
56 public FingerprintTrustManagerFactoryBuilder fingerprints(CharSequence... fingerprints) {
57 return fingerprints(Arrays.asList(checkNotNull(fingerprints, "fingerprints")));
58 }
59
60
61
62
63
64
65
66 public FingerprintTrustManagerFactoryBuilder fingerprints(Iterable<? extends CharSequence> fingerprints) {
67 checkNotNull(fingerprints, "fingerprints");
68 for (CharSequence fingerprint : fingerprints) {
69 checkNotNullWithIAE(fingerprint, "fingerprint");
70 this.fingerprints.add(fingerprint.toString());
71 }
72 return this;
73 }
74
75
76
77
78
79
80 public FingerprintTrustManagerFactory build() {
81 if (fingerprints.isEmpty()) {
82 throw new IllegalStateException("No fingerprints provided");
83 }
84 return new FingerprintTrustManagerFactory(this.algorithm,
85 FingerprintTrustManagerFactory.toFingerprintArray(this.fingerprints));
86 }
87 }