1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.handler.ssl;
17
18 import io.netty5.util.internal.EmptyArrays;
19
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.Set;
23
24
25
26
27 public final class IdentityCipherSuiteFilter implements CipherSuiteFilter {
28
29
30
31
32 public static final IdentityCipherSuiteFilter INSTANCE = new IdentityCipherSuiteFilter(true);
33
34
35
36
37 public static final IdentityCipherSuiteFilter INSTANCE_DEFAULTING_TO_SUPPORTED_CIPHERS =
38 new IdentityCipherSuiteFilter(false);
39
40 private final boolean defaultToDefaultCiphers;
41
42 private IdentityCipherSuiteFilter(boolean defaultToDefaultCiphers) {
43 this.defaultToDefaultCiphers = defaultToDefaultCiphers;
44 }
45
46 @Override
47 public String[] filterCipherSuites(Iterable<String> ciphers, List<String> defaultCiphers,
48 Set<String> supportedCiphers) {
49 if (ciphers == null) {
50 return defaultToDefaultCiphers ?
51 defaultCiphers.toArray(EmptyArrays.EMPTY_STRINGS) :
52 supportedCiphers.toArray(EmptyArrays.EMPTY_STRINGS);
53 } else {
54 List<String> newCiphers = new ArrayList<>(supportedCiphers.size());
55 for (String c : ciphers) {
56 if (c == null) {
57 break;
58 }
59 newCiphers.add(c);
60 }
61 return newCiphers.toArray(EmptyArrays.EMPTY_STRINGS);
62 }
63 }
64 }