From dcf082d139b458269f9ec8677ebcee4cece96e35 Mon Sep 17 00:00:00 2001 From: "Y. T. Chung" Date: Thu, 23 Oct 2014 23:29:02 +0800 Subject: [PATCH] fixed doc test, add travis --- .travis.yml | 5 +++++ README.md | 2 ++ src/config.rs | 1 + src/crypto/cipher.rs | 12 +++++++++++- src/crypto/openssl.rs | 7 +++++++ 5 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..192f28c7 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: rust + +script: + - cargo build -v + - cargo test -v diff --git a/README.md b/README.md index 60e9e5d3..86e15d15 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # shadowsocks-rust +[![Build Status](https://travis-ci.org/zonyitoo/shadowsocks-rust.svg)](https://travis-ci.org/zonyitoo/shadowsocks-rust) + This is a port of [shadowsocks](https://github.com/clowwindy/shadowsocks). shadowsocks is a fast tunnel proxy that helps you bypass firewalls. diff --git a/src/config.rs b/src/config.rs index b23608fd..e7a5b48f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -77,6 +77,7 @@ use std::option::Option; use crypto::cipher::CIPHER_AES_256_CFB; +/// Configuration for a server #[deriving(Clone, Show)] pub struct ServerConfig { pub address: String, diff --git a/src/crypto/cipher.rs b/src/crypto/cipher.rs index af7d8e69..25a95109 100644 --- a/src/crypto/cipher.rs +++ b/src/crypto/cipher.rs @@ -23,6 +23,7 @@ use crypto::openssl; +/// The trait for basic cipher methods pub trait Cipher { fn encrypt(&mut self, data: &[u8]) -> Vec; fn decrypt(&mut self, data: &[u8]) -> Vec; @@ -158,10 +159,19 @@ impl Cipher for CipherVariant { /// otherwise, it will generate a new cipher with the provided `key`. /// /// ```rust -/// let mut cipher = match cipher::with_name("cipher-aes-256-cfb", "cipher_password".as_bytes()) { +/// use shadowsocks::crypto::cipher; +/// use shadowsocks::crypto::cipher::Cipher; +/// +/// let mut cipher = match cipher::with_name("aes-256-cfb", "cipher_password".as_bytes()) { /// Some(cipher) => { cipher }, /// None => { fail!("Undefined cipher!") }, /// }; +/// +/// let message = "test message".as_bytes(); +/// let encrypted_message = cipher.encrypt(message); +/// let decrypted_message = cipher.decrypt(encrypted_message.as_slice()); +/// +/// assert!(decrypted_message.as_slice() == message); /// ``` /// /// *Note: The cipher have to be mutable if you want to use it for encrypting and decrypting.* diff --git a/src/crypto/openssl.rs b/src/crypto/openssl.rs index dcbbe667..fb59f8ab 100644 --- a/src/crypto/openssl.rs +++ b/src/crypto/openssl.rs @@ -132,6 +132,7 @@ extern { fn EVP_sha1() -> EVP_MD; } +/// This two modes will be converted into the last parameter of `EVP_CipherInit_ex`. enum CryptoMode { CryptoModeDecrypt, CryptoModeEncrypt, @@ -339,10 +340,16 @@ impl Drop for OpenSSLCrypto { /// *Note: This behavior works just the same as the official version of shadowsocks.* /// /// ```rust +/// use shadowsocks::crypto::cipher; +/// use shadowsocks::crypto::openssl::OpenSSLCipher; +/// use shadowsocks::crypto::cipher::Cipher; +/// /// let mut cipher = OpenSSLCipher::new(cipher::CipherTypeAes128Cfb, "password".as_bytes()); /// let message = "hello world"; /// let encrypted_message = cipher.encrypt(message.as_bytes()); /// let decrypted_message = cipher.decrypt(encrypted_message.as_slice()); +/// +/// assert!(decrypted_message.as_slice() == message.as_bytes()); /// ``` #[deriving(Clone)] pub struct OpenSSLCipher {