fixed doc test, add travis

This commit is contained in:
Y. T. Chung
2014-10-23 23:29:02 +08:00
parent 1593e20d28
commit dcf082d139
5 changed files with 26 additions and 1 deletions

5
.travis.yml Normal file
View File

@@ -0,0 +1,5 @@
language: rust
script:
- cargo build -v
- cargo test -v

View File

@@ -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.

View File

@@ -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,

View File

@@ -23,6 +23,7 @@
use crypto::openssl;
/// The trait for basic cipher methods
pub trait Cipher {
fn encrypt(&mut self, data: &[u8]) -> Vec<u8>;
fn decrypt(&mut self, data: &[u8]) -> Vec<u8>;
@@ -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.*

View File

@@ -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 {