pub struct SSConfig {
pub host: Host,
pub port: u16,
pub method: Method,
pub password: String,
pub tag: Option<String>,
pub extra: Option<HashMap<String, String>>,
}
Fields§
§host: Host
§port: u16
§method: Method
§password: String
§tag: Option<String>
§extra: Option<HashMap<String, String>>
Implementations§
Source§impl SSConfig
impl SSConfig
Sourcepub fn to_legacy_base64_encoded(&self) -> String
pub fn to_legacy_base64_encoded(&self) -> String
converts SSConfig to legacy base64 shadowsocks uri
use ss_uri::SSConfig;
use ss_uri::Method;
use url::Host;
let config = SSConfig {
host: Host::parse("192.168.100.1").unwrap(),
port: 8888,
method: Method::BfCfb,
password: "test".to_string(),
tag: Some("Foo Bar".to_string()),
extra: None,
};
assert_eq!(
config.to_legacy_base64_encoded(),
"ss://YmYtY2ZiOnRlc3RAMTkyLjE2OC4xMDAuMTo4ODg4#Foo%20Bar"
);
Sourcepub fn to_sip002(&self) -> String
pub fn to_sip002(&self) -> String
converts SSConfig to shadowsocks sip002 format
use ss_uri::SSConfig;
use ss_uri::Method;
use url::Host;
let config = SSConfig {
host: Host::parse("192.168.100.1").unwrap(),
port: 8888,
method: Method::Aes128Gcm,
password: "test".to_string(),
tag: Some("Foo Bar".to_string()),
extra: None,
};
assert_eq!(
config.to_sip002(),
"ss://YWVzLTEyOC1nY206dGVzdA@192.168.100.1:8888/#Foo%20Bar"
);
Sourcepub fn parse(s: &str) -> Result<Self, SSParseError>
pub fn parse(s: &str) -> Result<Self, SSParseError>
this is the method you should usually use for parsing shadowsocks uris parses an string into shadowsocks uri it supports both sip002 and legacy mode if both were invalid returns sip002’s error sip002 example:
use ss_uri::SSConfig;
use url::Host;
use ss_uri::Method;
let config = SSConfig::parse("ss://YWVzLTEyOC1nY206dGVzdA@192.168.100.1:8888#Foo%20Bar").unwrap();
assert_eq!(config.method, Method::Aes128Gcm);
assert_eq!(config.password,"test");
assert_eq!(config.host, Host::parse("192.168.100.1").unwrap());
assert_eq!(config.port, 8888);
assert_eq!(config.tag, Some("Foo Bar".to_string()));
legacy uri example:
use ss_uri::SSConfig;
use url::Host;
use ss_uri::Method;
let input = "ss://YmYtY2ZiOnRlc3RAMTkyLjE2OC4xMDAuMTo4ODg4#Foo Bar";
let config = SSConfig::parse_legacy_base64(input).unwrap();
assert_eq!(config.method, Method::BfCfb);
assert_eq!(config.password, "test");
assert_eq!(config.host, Host::parse("192.168.100.1").unwrap());
assert_eq!(config.port, 8888);
assert_eq!(config.tag, Some("Foo Bar".to_string()));
assert_eq!(config.extra, None);
pub fn parse_sip002(s: &str) -> Result<Self, SSParseError>
pub fn parse_legacy_base64(s: &str) -> Result<Self, SSParseError>
Trait Implementations§
impl Eq for SSConfig
impl StructuralPartialEq for SSConfig
Auto Trait Implementations§
impl Freeze for SSConfig
impl RefUnwindSafe for SSConfig
impl Send for SSConfig
impl Sync for SSConfig
impl Unpin for SSConfig
impl UnwindSafe for SSConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more