1package eu.siacs.conversations.http;
2
3import java.util.regex.Pattern;
4
5import okhttp3.HttpUrl;
6
7public final class AesGcmURL {
8
9 /**
10 * This matches a 48 or 44 byte IV + KEY hex combo, like used in http/aesgcm upload anchors
11 */
12 public static final Pattern IV_KEY = Pattern.compile("([A-Fa-f0-9]{2}){48}|([A-Fa-f0-9]{2}){44}");
13
14 public static final String PROTOCOL_NAME = "aesgcm";
15
16 private AesGcmURL() {
17
18 }
19
20 public static String toAesGcmUrl(HttpUrl url) {
21 if (url.isHttps()) {
22 return PROTOCOL_NAME + url.toString().substring(5);
23 } else {
24 return url.toString();
25 }
26 }
27
28 public static HttpUrl of(final String url) {
29 final int end = url.indexOf("://");
30 if (end < 0) {
31 throw new IllegalArgumentException("Scheme not found");
32 }
33 final String protocol = url.substring(0, end);
34 if (PROTOCOL_NAME.equals(protocol)) {
35 return HttpUrl.get("https" + url.substring(PROTOCOL_NAME.length()));
36 } else {
37 return HttpUrl.get(url);
38 }
39 }
40
41}