Skip to content

Commit

Permalink
Use "none" as dummy cipher's ID replacing "plain"
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed May 7, 2020
1 parent 0b84a85 commit 74d3c61
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/crypto/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const CIPHER_AES_128_PMAC_SIV: &str = "aes-128-pmac-siv";
const CIPHER_AES_256_PMAC_SIV: &str = "aes-256-pmac-siv";

const CIPHER_PLAIN: &str = "plain";
const CIPHER_NONE: &str = "none";

const CIPHER_AES_128_GCM: &str = "aes-128-gcm";
const CIPHER_AES_256_GCM: &str = "aes-256-gcm";
Expand All @@ -171,6 +172,7 @@ const CIPHER_XCHACHA20_IETF_POLY1305: &str = "xchacha20-ietf-poly1305";
pub enum CipherType {
Table,
Plain,
None,

#[cfg(feature = "aes-cfb")]
Aes128Cfb,
Expand Down Expand Up @@ -271,7 +273,7 @@ impl CipherType {
/// Symmetric crypto key size
pub fn key_size(self) -> usize {
match self {
CipherType::Table | CipherType::Plain => 0,
CipherType::Table | CipherType::Plain | CipherType::None => 0,

#[cfg(feature = "aes-cfb")]
CipherType::Aes128Cfb1 => symm::Cipher::aes_128_cfb1().key_len(),
Expand Down Expand Up @@ -402,7 +404,7 @@ impl CipherType {
/// Symmetric crypto initialize vector size
pub fn iv_size(self) -> usize {
match self {
CipherType::Table | CipherType::Plain => 0,
CipherType::Table | CipherType::Plain | CipherType::None => 0,

#[cfg(feature = "aes-cfb")]
CipherType::Aes128Cfb1 => symm::Cipher::aes_128_cfb1().iv_len().unwrap_or(0),
Expand Down Expand Up @@ -595,6 +597,7 @@ impl CipherType {
match self {
CipherType::Table => CIPHER_TABLE,
CipherType::Plain => CIPHER_PLAIN,
CipherType::None => CIPHER_NONE,
#[cfg(feature = "aes-cfb")]
CipherType::Aes128Cfb => CIPHER_AES_128_CFB,
#[cfg(feature = "aes-cfb")]
Expand Down Expand Up @@ -689,6 +692,8 @@ impl FromStr for CipherType {
match s {
CIPHER_TABLE | "" => Ok(CipherType::Table),
CIPHER_PLAIN => Ok(CipherType::Plain),
CIPHER_NONE => Ok(CipherType::None),

#[cfg(feature = "aes-cfb")]
CIPHER_AES_128_CFB => Ok(CipherType::Aes128Cfb),
#[cfg(feature = "aes-cfb")]
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn new_stream(t: CipherType, key: &[u8], iv: &[u8], mode: CryptoMode) -> Box

match t {
CipherType::Table => Box::new(table::TableCipher::new(key, mode)),
CipherType::Plain => Box::new(dummy::DummyCipher),
CipherType::Plain | CipherType::None => Box::new(dummy::DummyCipher),

#[cfg(feature = "sodium")]
CipherType::ChaCha20 | CipherType::Salsa20 | CipherType::XSalsa20 | CipherType::ChaCha20Ietf => {
Expand Down

0 comments on commit 74d3c61

Please sign in to comment.