mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-02-09 01:59:16 +08:00
fixed doc test, add travis
This commit is contained in:
5
.travis.yml
Normal file
5
.travis.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
language: rust
|
||||
|
||||
script:
|
||||
- cargo build -v
|
||||
- cargo test -v
|
||||
@@ -1,5 +1,7 @@
|
||||
# shadowsocks-rust
|
||||
|
||||
[](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.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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.*
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user