Пример #1
0
  /**
   * Builds a URI scheme name given the parameters for a {@code HostAuth}. If a {@code clientAlias}
   * is provided, this indicates that a secure connection must be used.
   */
  public static String getSchemeString(String protocol, int flags, String clientAlias) {
    String security = "";
    switch (flags & USER_CONFIG_MASK) {
      case FLAG_SSL:
        security = "+ssl+";
        break;
      case FLAG_SSL | FLAG_TRUST_ALL:
        security = "+ssl+trustallcerts";
        break;
      case FLAG_TLS:
        security = "+tls+";
        break;
      case FLAG_TLS | FLAG_TRUST_ALL:
        security = "+tls+trustallcerts";
        break;
    }

    if (!TextUtils.isEmpty(clientAlias)) {
      if (TextUtils.isEmpty(security)) {
        throw new IllegalArgumentException(
            "Can't specify a certificate alias for a non-secure connection");
      }
      if (!security.endsWith("+")) {
        security += "+";
      }
      security += SSLUtils.escapeForSchemeName(clientAlias);
    }

    return protocol + security;
  }