ShadowSocksURL constructor

ShadowSocksURL({
  1. required String url,
})

Implementation

ShadowSocksURL({required super.url}) {
  if (!url.startsWith('ss://')) {
    throw ArgumentError('url is invalid');
  }
  final temp = Uri.tryParse(url);
  if (temp == null) {
    throw ArgumentError('url is invalid');
  }
  uri = temp;
  if (uri.userInfo.isNotEmpty) {
    String raw = uri.userInfo;
    if (raw.length % 4 > 0) {
      raw += "=" * (4 - raw.length % 4);
    }
    try {
      final methodpass = utf8.decode(base64Decode(raw));
      method = methodpass.split(':')[0];
      password = methodpass.substring(method.length + 1);
    } catch (_) {}
  }

  if (uri.queryParameters.isNotEmpty) {
    var sni = super.populateTransportSettings(
      transport: uri.queryParameters['type'] ?? "tcp",
      headerType: uri.queryParameters['headerType'],
      host: uri.queryParameters["host"],
      path: uri.queryParameters["path"],
      seed: uri.queryParameters["seed"],
      quicSecurity: uri.queryParameters["quicSecurity"],
      key: uri.queryParameters["key"],
      mode: uri.queryParameters["mode"],
      serviceName: uri.queryParameters["serviceName"],
    );
    super.populateTlsSettings(
      streamSecurity: uri.queryParameters['security'] ?? '',
      allowInsecure: allowInsecure,
      sni: uri.queryParameters["sni"] ?? sni,
      fingerprint: streamSetting['tlsSettings']?['fingerprint'],
      alpns: uri.queryParameters['alpn'],
      publicKey: null,
      shortId: null,
      spiderX: null,
    );
  }
}