mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-02-09 01:59:16 +08:00
Add dummy cipher
This commit is contained in:
@@ -31,6 +31,7 @@ use crypto::openssl;
|
||||
use crypto::table;
|
||||
use crypto::CryptoMode;
|
||||
use crypto::rc4_md5;
|
||||
use crypto::dummy;
|
||||
use crypto::crypto::CryptoCipher;
|
||||
|
||||
use crypto::digest::{self, DigestType};
|
||||
@@ -120,9 +121,12 @@ const CIPHER_CHACHA20: &'static str = "chacha20";
|
||||
#[cfg(feature = "cipher-salsa20")]
|
||||
const CIPHER_SALSA20: &'static str = "salsa20";
|
||||
|
||||
const CIPHER_DUMMY: &'static str = "dummy";
|
||||
|
||||
#[derive(Clone, Debug, Copy)]
|
||||
pub enum CipherType {
|
||||
Table,
|
||||
Dummy,
|
||||
|
||||
#[cfg(feature = "cipher-aes-cfb")]
|
||||
Aes128Cfb,
|
||||
@@ -157,6 +161,7 @@ impl CipherType {
|
||||
pub fn block_size(&self) -> usize {
|
||||
match *self {
|
||||
CipherType::Table => 0,
|
||||
CipherType::Dummy => 0,
|
||||
|
||||
#[cfg(feature = "cipher-aes-cfb")]
|
||||
CipherType::Aes128Cfb => symm::Type::AES_128_CFB128.block_size(),
|
||||
@@ -186,6 +191,7 @@ impl CipherType {
|
||||
pub fn key_size(&self) -> usize {
|
||||
match *self {
|
||||
CipherType::Table => 0,
|
||||
CipherType::Dummy => 0,
|
||||
|
||||
#[cfg(feature = "cipher-aes-cfb")]
|
||||
CipherType::Aes128Cfb => symm::Type::AES_128_CFB128.key_len(),
|
||||
@@ -243,6 +249,7 @@ impl CipherType {
|
||||
pub fn iv_size(&self) -> usize {
|
||||
match *self {
|
||||
CipherType::Table => 0,
|
||||
CipherType::Dummy => 0,
|
||||
|
||||
#[cfg(feature = "cipher-aes-cfb")]
|
||||
CipherType::Aes128Cfb => symm::Type::AES_128_CFB128.iv_len().unwrap_or(0),
|
||||
@@ -286,6 +293,7 @@ impl FromStr for CipherType {
|
||||
fn from_str(s: &str) -> Result<CipherType, Error> {
|
||||
match s {
|
||||
CIPHER_TABLE | "" => Ok(CipherType::Table),
|
||||
CIPHER_DUMMY => Ok(CipherType::Dummy),
|
||||
#[cfg(feature = "cipher-aes-cfb")]
|
||||
CIPHER_AES_128_CFB => Ok(CipherType::Aes128Cfb),
|
||||
#[cfg(feature = "cipher-aes-cfb")]
|
||||
@@ -323,6 +331,7 @@ impl Display for CipherType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
CipherType::Table => write!(f, "{}", CIPHER_TABLE),
|
||||
CipherType::Dummy => write!(f, "{}", CIPHER_DUMMY),
|
||||
#[cfg(feature = "cipher-aes-cfb")]
|
||||
CipherType::Aes128Cfb => write!(f, "{}", CIPHER_AES_128_CFB),
|
||||
#[cfg(feature = "cipher-aes-cfb")]
|
||||
@@ -400,6 +409,7 @@ macro_rules! define_ciphers {
|
||||
|
||||
define_ciphers! {
|
||||
TableCipher => table::TableCipher,
|
||||
DummyCipher => dummy::DummyCipher,
|
||||
Rc4Md5Cipher => rc4_md5::Rc4Md5Cipher,
|
||||
OpenSSLCipher => openssl::OpenSSLCipher,
|
||||
CryptoCipher => CryptoCipher,
|
||||
@@ -409,6 +419,7 @@ define_ciphers! {
|
||||
pub fn with_type(t: CipherType, key: &[u8], iv: &[u8], mode: CryptoMode) -> CipherVariant {
|
||||
match t {
|
||||
CipherType::Table => CipherVariant::new(table::TableCipher::new(key, mode)),
|
||||
CipherType::Dummy => CipherVariant::new(dummy::DummyCipher),
|
||||
|
||||
#[cfg(feature = "cipher-chacha20")]
|
||||
CipherType::ChaCha20 => CipherVariant::new(CryptoCipher::new(t, key, iv)),
|
||||
|
||||
35
src/crypto/dummy.rs
Normal file
35
src/crypto/dummy.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
// The MIT License (MIT)
|
||||
|
||||
// Copyright (c) 2014 Y. T. CHUNG <zonyitoo@gmail.com>
|
||||
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
// this software and associated documentation files (the "Software"), to deal in
|
||||
// the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
// subject to the following conditions:
|
||||
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
use super::{Cipher, CipherResult};
|
||||
|
||||
pub struct DummyCipher;
|
||||
|
||||
impl Cipher for DummyCipher {
|
||||
fn update(&mut self, data: &[u8], out: &mut Vec<u8>) -> CipherResult<()> {
|
||||
out.extend_from_slice(data);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn finalize(&mut self, _: &mut Vec<u8>) -> CipherResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ use std::convert::From;
|
||||
|
||||
use openssl::crypto::symm;
|
||||
|
||||
pub use self::cipher::{CipherType, Cipher, CipherVariant};
|
||||
pub use self::cipher::{CipherType, Cipher, CipherVariant, CipherResult};
|
||||
|
||||
pub mod cipher;
|
||||
pub mod openssl;
|
||||
@@ -34,6 +34,7 @@ pub mod digest;
|
||||
pub mod table;
|
||||
pub mod rc4_md5;
|
||||
pub mod crypto;
|
||||
pub mod dummy;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum CryptoMode {
|
||||
|
||||
Reference in New Issue
Block a user