Skip to content

Commit f302298

Browse files
committed
Add dummy cipher
1 parent b24f4c9 commit f302298

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

src/crypto/cipher.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use crypto::openssl;
3131
use crypto::table;
3232
use crypto::CryptoMode;
3333
use crypto::rc4_md5;
34+
use crypto::dummy;
3435
use crypto::crypto::CryptoCipher;
3536

3637
use crypto::digest::{self, DigestType};
@@ -120,9 +121,12 @@ const CIPHER_CHACHA20: &'static str = "chacha20";
120121
#[cfg(feature = "cipher-salsa20")]
121122
const CIPHER_SALSA20: &'static str = "salsa20";
122123

124+
const CIPHER_DUMMY: &'static str = "dummy";
125+
123126
#[derive(Clone, Debug, Copy)]
124127
pub enum CipherType {
125128
Table,
129+
Dummy,
126130

127131
#[cfg(feature = "cipher-aes-cfb")]
128132
Aes128Cfb,
@@ -157,6 +161,7 @@ impl CipherType {
157161
pub fn block_size(&self) -> usize {
158162
match *self {
159163
CipherType::Table => 0,
164+
CipherType::Dummy => 0,
160165

161166
#[cfg(feature = "cipher-aes-cfb")]
162167
CipherType::Aes128Cfb => symm::Type::AES_128_CFB128.block_size(),
@@ -186,6 +191,7 @@ impl CipherType {
186191
pub fn key_size(&self) -> usize {
187192
match *self {
188193
CipherType::Table => 0,
194+
CipherType::Dummy => 0,
189195

190196
#[cfg(feature = "cipher-aes-cfb")]
191197
CipherType::Aes128Cfb => symm::Type::AES_128_CFB128.key_len(),
@@ -243,6 +249,7 @@ impl CipherType {
243249
pub fn iv_size(&self) -> usize {
244250
match *self {
245251
CipherType::Table => 0,
252+
CipherType::Dummy => 0,
246253

247254
#[cfg(feature = "cipher-aes-cfb")]
248255
CipherType::Aes128Cfb => symm::Type::AES_128_CFB128.iv_len().unwrap_or(0),
@@ -286,6 +293,7 @@ impl FromStr for CipherType {
286293
fn from_str(s: &str) -> Result<CipherType, Error> {
287294
match s {
288295
CIPHER_TABLE | "" => Ok(CipherType::Table),
296+
CIPHER_DUMMY => Ok(CipherType::Dummy),
289297
#[cfg(feature = "cipher-aes-cfb")]
290298
CIPHER_AES_128_CFB => Ok(CipherType::Aes128Cfb),
291299
#[cfg(feature = "cipher-aes-cfb")]
@@ -323,6 +331,7 @@ impl Display for CipherType {
323331
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
324332
match *self {
325333
CipherType::Table => write!(f, "{}", CIPHER_TABLE),
334+
CipherType::Dummy => write!(f, "{}", CIPHER_DUMMY),
326335
#[cfg(feature = "cipher-aes-cfb")]
327336
CipherType::Aes128Cfb => write!(f, "{}", CIPHER_AES_128_CFB),
328337
#[cfg(feature = "cipher-aes-cfb")]
@@ -400,6 +409,7 @@ macro_rules! define_ciphers {
400409

401410
define_ciphers! {
402411
TableCipher => table::TableCipher,
412+
DummyCipher => dummy::DummyCipher,
403413
Rc4Md5Cipher => rc4_md5::Rc4Md5Cipher,
404414
OpenSSLCipher => openssl::OpenSSLCipher,
405415
CryptoCipher => CryptoCipher,
@@ -409,6 +419,7 @@ define_ciphers! {
409419
pub fn with_type(t: CipherType, key: &[u8], iv: &[u8], mode: CryptoMode) -> CipherVariant {
410420
match t {
411421
CipherType::Table => CipherVariant::new(table::TableCipher::new(key, mode)),
422+
CipherType::Dummy => CipherVariant::new(dummy::DummyCipher),
412423

413424
#[cfg(feature = "cipher-chacha20")]
414425
CipherType::ChaCha20 => CipherVariant::new(CryptoCipher::new(t, key, iv)),

src/crypto/dummy.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// The MIT License (MIT)
2+
3+
// Copyright (c) 2014 Y. T. CHUNG <zonyitoo@gmail.com>
4+
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
// this software and associated documentation files (the "Software"), to deal in
7+
// the Software without restriction, including without limitation the rights to
8+
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
// the Software, and to permit persons to whom the Software is furnished to do so,
10+
// subject to the following conditions:
11+
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
use super::{Cipher, CipherResult};
23+
24+
pub struct DummyCipher;
25+
26+
impl Cipher for DummyCipher {
27+
fn update(&mut self, data: &[u8], out: &mut Vec<u8>) -> CipherResult<()> {
28+
out.extend_from_slice(data);
29+
Ok(())
30+
}
31+
32+
fn finalize(&mut self, _: &mut Vec<u8>) -> CipherResult<()> {
33+
Ok(())
34+
}
35+
}

src/crypto/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ use std::convert::From;
2626

2727
use openssl::crypto::symm;
2828

29-
pub use self::cipher::{CipherType, Cipher, CipherVariant};
29+
pub use self::cipher::{CipherType, Cipher, CipherVariant, CipherResult};
3030

3131
pub mod cipher;
3232
pub mod openssl;
3333
pub mod digest;
3434
pub mod table;
3535
pub mod rc4_md5;
3636
pub mod crypto;
37+
pub mod dummy;
3738

3839
#[derive(Clone, Copy)]
3940
pub enum CryptoMode {

0 commit comments

Comments
 (0)