Skip to content

Commit e095db3

Browse files
committed
reformatted
1 parent 8e4a6d5 commit e095db3

File tree

26 files changed

+268
-302
lines changed

26 files changed

+268
-302
lines changed

rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ condense_wildcard_suffixes = true
99
#fn_call_style = "Visual"
1010
#chain_indent = "Visual"
1111
normalize_comments = true
12-
use_try_shorthand = true
12+
use_try_shorthand = true

src/bin/local.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! You have to provide all needed configuration attributes via command line parameters,
44
//! or you could specify a configuration file. The format of configuration file is defined
55
//! in mod `config`.
6-
//!
6+
//!
77
88
extern crate clap;
99
extern crate env_logger;
@@ -18,12 +18,12 @@ use std::env;
1818
use std::io::{self, Write};
1919
use std::net::SocketAddr;
2020

21-
use env_logger::Builder;
2221
use env_logger::fmt::Formatter;
22+
use env_logger::Builder;
2323
use log::{LevelFilter, Record};
2424

25-
use shadowsocks::{run_local, Config, ConfigType, ServerAddr, ServerConfig};
2625
use shadowsocks::plugin::PluginConfig;
26+
use shadowsocks::{run_local, Config, ConfigType, ServerAddr, ServerConfig};
2727

2828
fn log_time(fmt: &mut Formatter, without_time: bool, record: &Record) -> io::Result<()> {
2929
if without_time {
@@ -148,18 +148,16 @@ fn main() {
148148
let mut has_provided_config = false;
149149

150150
let mut config = match matches.value_of("CONFIG") {
151-
Some(cpath) => {
152-
match Config::load_from_file(cpath, ConfigType::Local) {
153-
Ok(cfg) => {
154-
has_provided_config = true;
155-
cfg
156-
}
157-
Err(err) => {
158-
error!("{:?}", err);
159-
return;
160-
}
151+
Some(cpath) => match Config::load_from_file(cpath, ConfigType::Local) {
152+
Ok(cfg) => {
153+
has_provided_config = true;
154+
cfg
161155
}
162-
}
156+
Err(err) => {
157+
error!("{:?}", err);
158+
return;
159+
}
160+
},
163161
None => Config::new(),
164162
};
165163

@@ -201,8 +199,7 @@ fn main() {
201199

202200
let has_provided_local_config = match matches.value_of("LOCAL_ADDR") {
203201
Some(local_addr) => {
204-
let local_addr: SocketAddr = local_addr.parse()
205-
.expect("`local-addr` is not a valid IP address");
202+
let local_addr: SocketAddr = local_addr.parse().expect("`local-addr` is not a valid IP address");
206203

207204
config.local = Some(local_addr);
208205
true

src/bin/server.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ use std::io::{self, Write};
1919

2020
use clap::{App, Arg};
2121

22-
use env_logger::Builder;
2322
use env_logger::fmt::Formatter;
23+
use env_logger::Builder;
2424
use log::{LevelFilter, Record};
2525

26-
use shadowsocks::{run_server, Config, ConfigType, ServerAddr, ServerConfig};
2726
use shadowsocks::plugin::PluginConfig;
27+
use shadowsocks::{run_server, Config, ConfigType, ServerAddr, ServerConfig};
2828

2929
fn log_time(fmt: &mut Formatter, without_time: bool, record: &Record) -> io::Result<()> {
3030
if without_time {
@@ -129,18 +129,16 @@ fn main() {
129129

130130
let mut has_provided_config = false;
131131
let mut config = match matches.value_of("CONFIG") {
132-
Some(cpath) => {
133-
match Config::load_from_file(cpath, ConfigType::Server) {
134-
Ok(cfg) => {
135-
has_provided_config = true;
136-
cfg
137-
}
138-
Err(err) => {
139-
error!("{:?}", err);
140-
return;
141-
}
132+
Some(cpath) => match Config::load_from_file(cpath, ConfigType::Server) {
133+
Ok(cfg) => {
134+
has_provided_config = true;
135+
cfg
142136
}
143-
}
137+
Err(err) => {
138+
error!("{:?}", err);
139+
return;
140+
}
141+
},
144142
None => Config::new(),
145143
};
146144

src/bin/ssdns.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,16 @@ fn main() {
131131
let mut has_provided_config = false;
132132

133133
let mut config = match matches.value_of("CONFIG") {
134-
Some(cpath) => {
135-
match Config::load_from_file(cpath, ConfigType::Local) {
136-
Ok(cfg) => {
137-
has_provided_config = true;
138-
cfg
139-
}
140-
Err(err) => {
141-
error!("{:?}", err);
142-
return;
143-
}
134+
Some(cpath) => match Config::load_from_file(cpath, ConfigType::Local) {
135+
Ok(cfg) => {
136+
has_provided_config = true;
137+
cfg
144138
}
145-
}
139+
Err(err) => {
140+
error!("{:?}", err);
141+
return;
142+
}
143+
},
146144
None => Config::new(),
147145
};
148146

src/bin/ssurl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ extern crate shadowsocks;
1010

1111
use clap::{App, Arg};
1212

13-
use qrcode::QrCode;
1413
use qrcode::types::Color;
14+
use qrcode::QrCode;
1515

16-
use shadowsocks::VERSION;
1716
use shadowsocks::config::{Config, ConfigType, ServerConfig};
17+
use shadowsocks::VERSION;
1818

1919
const BLACK: &'static str = "\x1b[40m \x1b[0m";
2020
const WHITE: &'static str = "\x1b[47m \x1b[0m";

src/config.rs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,10 @@ impl FromStr for ServerAddr {
138138
Err(..) => {
139139
let mut sp = s.split(':');
140140
match (sp.next(), sp.next()) {
141-
(Some(dn), Some(port)) => {
142-
match port.parse::<u16>() {
143-
Ok(port) => Ok(ServerAddr::DomainName(dn.to_owned(), port)),
144-
Err(..) => Err(ServerAddrError),
145-
}
146-
}
141+
(Some(dn), Some(port)) => match port.parse::<u16>() {
142+
Ok(port) => Ok(ServerAddr::DomainName(dn.to_owned(), port)),
143+
Err(..) => Err(ServerAddrError),
144+
},
147145
_ => Err(ServerAddrError),
148146
}
149147
}
@@ -287,14 +285,12 @@ impl ServerConfig {
287285

288286
let user_info = parsed.username();
289287
let account = match decode_config(user_info, URL_SAFE_NO_PAD) {
290-
Ok(account) => {
291-
match String::from_utf8(account) {
292-
Ok(ac) => ac,
293-
Err(..) => {
294-
return Err(UrlParseError::InvalidAuthInfo);
295-
}
288+
Ok(account) => match String::from_utf8(account) {
289+
Ok(ac) => ac,
290+
Err(..) => {
291+
return Err(UrlParseError::InvalidAuthInfo);
296292
}
297-
}
293+
},
298294
Err(err) => {
299295
error!("Failed to parse UserInfo with Base64, err: {}", err);
300296
return Err(UrlParseError::InvalidUserInfo);
@@ -679,17 +675,15 @@ impl Config {
679675

680676
match addr_str.parse::<Ipv4Addr>() {
681677
Ok(ip) => Some(SocketAddr::V4(SocketAddrV4::new(ip, port))),
682-
Err(..) => {
683-
match addr_str.parse::<Ipv6Addr>() {
684-
Ok(ip) => Some(SocketAddr::V6(SocketAddrV6::new(ip, port, 0, 0))),
685-
Err(..) => {
686-
return Err(Error::new(ErrorKind::Malformed,
687-
"`local_address` is not a valid IP \
688-
address",
689-
None))
690-
}
678+
Err(..) => match addr_str.parse::<Ipv6Addr>() {
679+
Ok(ip) => Some(SocketAddr::V6(SocketAddrV6::new(ip, port, 0, 0))),
680+
Err(..) => {
681+
return Err(Error::new(ErrorKind::Malformed,
682+
"`local_address` is not a valid IP \
683+
address",
684+
None))
691685
}
692-
}
686+
},
693687
}
694688
}
695689
None => None,
@@ -739,15 +733,17 @@ impl Config {
739733
let err = Error::new(ErrorKind::Malformed, "`dns` should be string", None);
740734
return Err(err);
741735
}
742-
Some(dns) => match dns.parse::<IpAddr>() {
743-
Err(..) => {
744-
let err = Error::new(ErrorKind::Malformed, "`dns` should be IpAddr", None);
745-
return Err(err);
746-
}
747-
Ok(addr) => {
748-
config.dns = SocketAddr::new(addr, 53);
736+
Some(dns) => {
737+
match dns.parse::<IpAddr>() {
738+
Err(..) => {
739+
let err = Error::new(ErrorKind::Malformed, "`dns` should be IpAddr", None);
740+
return Err(err);
741+
}
742+
Ok(addr) => {
743+
config.dns = SocketAddr::new(addr, 53);
744+
}
749745
}
750-
},
746+
}
751747
}
752748
}
753749

src/crypto/cipher.rs

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,24 @@ pub enum CipherType {
121121
Rc4,
122122
Rc4Md5,
123123

124-
#[cfg(feature = "sodium")] ChaCha20,
125-
#[cfg(feature = "sodium")] Salsa20,
126-
#[cfg(feature = "sodium")] XSalsa20,
127-
#[cfg(feature = "sodium")] ChaCha20Ietf,
124+
#[cfg(feature = "sodium")]
125+
ChaCha20,
126+
#[cfg(feature = "sodium")]
127+
Salsa20,
128+
#[cfg(feature = "sodium")]
129+
XSalsa20,
130+
#[cfg(feature = "sodium")]
131+
ChaCha20Ietf,
128132

129133
Aes128Gcm,
130134
Aes256Gcm,
131135

132136
ChaCha20Poly1305,
133137

134-
#[cfg(feature = "miscreant")] Aes128PmacSiv,
135-
#[cfg(feature = "miscreant")] Aes256PmacSiv,
138+
#[cfg(feature = "miscreant")]
139+
Aes128PmacSiv,
140+
#[cfg(feature = "miscreant")]
141+
Aes256PmacSiv,
136142
}
137143

138144
/// Category of ciphers
@@ -215,35 +221,24 @@ impl CipherType {
215221
match *self {
216222
CipherType::Table | CipherType::Plain => 0,
217223

218-
CipherType::Aes128Cfb1 => {
219-
symm::Cipher::aes_128_cfb1().iv_len()
220-
.expect("iv_len should not be None")
221-
}
222-
CipherType::Aes128Cfb8 => {
223-
symm::Cipher::aes_128_cfb8().iv_len()
224-
.expect("iv_len should not be None")
225-
}
224+
CipherType::Aes128Cfb1 => symm::Cipher::aes_128_cfb1().iv_len()
225+
.expect("iv_len should not be None"),
226+
CipherType::Aes128Cfb8 => symm::Cipher::aes_128_cfb8().iv_len()
227+
.expect("iv_len should not be None"),
226228
CipherType::Aes128Cfb | CipherType::Aes128Cfb128 => {
227229
symm::Cipher::aes_128_cfb128().iv_len()
228230
.expect("iv_len should not be None")
229231
}
230-
CipherType::Aes256Cfb1 => {
231-
symm::Cipher::aes_256_cfb1().iv_len()
232-
.expect("iv_len should not be None")
233-
}
234-
CipherType::Aes256Cfb8 => {
235-
symm::Cipher::aes_256_cfb8().iv_len()
236-
.expect("iv_len should not be None")
237-
}
232+
CipherType::Aes256Cfb1 => symm::Cipher::aes_256_cfb1().iv_len()
233+
.expect("iv_len should not be None"),
234+
CipherType::Aes256Cfb8 => symm::Cipher::aes_256_cfb8().iv_len()
235+
.expect("iv_len should not be None"),
238236
CipherType::Aes256Cfb | CipherType::Aes256Cfb128 => {
239237
symm::Cipher::aes_256_cfb128().iv_len()
240238
.expect("iv_len should not be None")
241239
}
242240

243-
CipherType::Rc4 => {
244-
symm::Cipher::rc4().iv_len()
245-
.expect("iv_len should not be None")
246-
}
241+
CipherType::Rc4 => symm::Cipher::rc4().iv_len().expect("iv_len should not be None"),
247242
CipherType::Rc4Md5 => 16,
248243

249244
#[cfg(feature = "sodium")]
@@ -410,29 +405,21 @@ impl Display for CipherType {
410405

411406
#[cfg(test)]
412407
mod test_cipher {
413-
use crypto::{new_stream, CipherType, StreamCipher};
414408
use crypto::CryptoMode;
409+
use crypto::{new_stream, CipherType, StreamCipher};
415410

416411
#[test]
417412
fn test_get_cipher() {
418413
let key = CipherType::Aes128Cfb.bytes_to_key(b"PassWORD");
419414
let iv = CipherType::Aes128Cfb.gen_init_vec();
420-
let mut encryptor = new_stream(CipherType::Aes128Cfb,
421-
&key[0..],
422-
&iv[0..],
423-
CryptoMode::Encrypt);
424-
let mut decryptor = new_stream(CipherType::Aes128Cfb,
425-
&key[0..],
426-
&iv[0..],
427-
CryptoMode::Decrypt);
415+
let mut encryptor = new_stream(CipherType::Aes128Cfb, &key[0..], &iv[0..], CryptoMode::Encrypt);
416+
let mut decryptor = new_stream(CipherType::Aes128Cfb, &key[0..], &iv[0..], CryptoMode::Decrypt);
428417
let message = "HELLO WORLD";
429418

430419
let mut encrypted_msg = Vec::new();
431-
encryptor.update(message.as_bytes(), &mut encrypted_msg)
432-
.unwrap();
420+
encryptor.update(message.as_bytes(), &mut encrypted_msg).unwrap();
433421
let mut decrypted_msg = Vec::new();
434-
decryptor.update(&encrypted_msg[..], &mut decrypted_msg)
435-
.unwrap();
422+
decryptor.update(&encrypted_msg[..], &mut decrypted_msg).unwrap();
436423

437424
assert!(message.as_bytes() == &decrypted_msg[..]);
438425
}

src/crypto/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,25 @@ use std::convert::From;
44

55
use openssl::symm;
66

7-
pub use self::aead::{new_aead_decryptor, new_aead_encryptor, AeadDecryptor, AeadEncryptor, BoxAeadDecryptor,
8-
BoxAeadEncryptor};
7+
pub use self::aead::{
8+
new_aead_decryptor, new_aead_encryptor, AeadDecryptor, AeadEncryptor, BoxAeadDecryptor, BoxAeadEncryptor,
9+
};
910
pub use self::cipher::{CipherCategory, CipherResult, CipherType};
1011
pub use self::stream::{new_stream, StreamCipher, StreamCipherVariant};
1112

13+
pub mod aead;
1214
pub mod cipher;
13-
pub mod openssl;
1415
pub mod digest;
15-
pub mod table;
16+
pub mod dummy;
17+
pub mod openssl;
1618
pub mod rc4_md5;
1719
pub mod ring;
18-
pub mod dummy;
19-
pub mod aead;
20-
pub mod stream;
2120
#[cfg(feature = "miscreant")]
2221
pub mod siv;
2322
#[cfg(feature = "sodium")]
2423
pub mod sodium;
24+
pub mod stream;
25+
pub mod table;
2526

2627
/// Crypto mode, encrypt or decrypt
2728
#[derive(Clone, Copy, Eq, PartialEq, Debug)]

0 commit comments

Comments
 (0)