1package eu.siacs.conversations.crypto.sasl;
2
3import android.util.Log;
4
5import com.google.common.base.CaseFormat;
6
7import java.util.Collection;
8
9import eu.siacs.conversations.Config;
10
11public enum ChannelBinding {
12 NONE,
13 TLS_EXPORTER,
14 TLS_SERVER_END_POINT,
15 TLS_UNIQUE;
16
17 public static ChannelBinding of(final String type) {
18 if (type == null) {
19 return null;
20 }
21 try {
22 return valueOf(
23 CaseFormat.LOWER_HYPHEN.converterTo(CaseFormat.UPPER_UNDERSCORE).convert(type));
24 } catch (final IllegalArgumentException e) {
25 Log.d(Config.LOGTAG, type + " is not a known channel binding");
26 return null;
27 }
28 }
29
30 public static ChannelBinding best(final Collection<ChannelBinding> bindings) {
31 if (bindings.contains(TLS_EXPORTER)) {
32 return TLS_EXPORTER;
33 } else if (bindings.contains(TLS_UNIQUE)) {
34 return TLS_UNIQUE;
35 } else if (bindings.contains(TLS_SERVER_END_POINT)) {
36 return TLS_SERVER_END_POINT;
37 } else {
38 return null;
39 }
40 }
41}