ShadowSocksURL constructor
ShadowSocksURL({
- required String url,
Creates a ShadowSocksURL by parsing the provided ss share link string.
Throws ArgumentError if the url does not start with ss://
or
cannot be decoded into a valid URI.
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) {
var 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) {
final 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,
);
}
}