SSConfig

Struct SSConfig 

Source
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

Source

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"
);
Source

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"
);
Source

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);
Source

pub fn parse_sip002(s: &str) -> Result<Self, SSParseError>

Source

pub fn parse_legacy_base64(s: &str) -> Result<Self, SSParseError>

Trait Implementations§

Source§

impl Clone for SSConfig

Source§

fn clone(&self) -> SSConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SSConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for SSConfig

Source§

fn eq(&self, other: &SSConfig) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for SSConfig

Source§

impl StructuralPartialEq for SSConfig

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,