@@ -121,18 +121,24 @@ pub enum CipherType {
121121 Rc4 ,
122122 Rc4Md5 ,
123123
124- #[ cfg( feature = "sodium" ) ] ChaCha20 ,
125- #[ cfg( feature = "sodium" ) ] Salsa20 ,
126- #[ cfg( feature = "sodium" ) ] XSalsa20 ,
127- #[ cfg( feature = "sodium" ) ] ChaCha20Ietf ,
124+ #[ cfg( feature = "sodium" ) ]
125+ ChaCha20 ,
126+ #[ cfg( feature = "sodium" ) ]
127+ Salsa20 ,
128+ #[ cfg( feature = "sodium" ) ]
129+ XSalsa20 ,
130+ #[ cfg( feature = "sodium" ) ]
131+ ChaCha20Ietf ,
128132
129133 Aes128Gcm ,
130134 Aes256Gcm ,
131135
132136 ChaCha20Poly1305 ,
133137
134- #[ cfg( feature = "miscreant" ) ] Aes128PmacSiv ,
135- #[ cfg( feature = "miscreant" ) ] Aes256PmacSiv ,
138+ #[ cfg( feature = "miscreant" ) ]
139+ Aes128PmacSiv ,
140+ #[ cfg( feature = "miscreant" ) ]
141+ Aes256PmacSiv ,
136142}
137143
138144/// Category of ciphers
@@ -215,35 +221,24 @@ impl CipherType {
215221 match * self {
216222 CipherType :: Table | CipherType :: Plain => 0 ,
217223
218- CipherType :: Aes128Cfb1 => {
219- symm:: Cipher :: aes_128_cfb1 ( ) . iv_len ( )
220- . expect ( "iv_len should not be None" )
221- }
222- CipherType :: Aes128Cfb8 => {
223- symm:: Cipher :: aes_128_cfb8 ( ) . iv_len ( )
224- . expect ( "iv_len should not be None" )
225- }
224+ CipherType :: Aes128Cfb1 => symm:: Cipher :: aes_128_cfb1 ( ) . iv_len ( )
225+ . expect ( "iv_len should not be None" ) ,
226+ CipherType :: Aes128Cfb8 => symm:: Cipher :: aes_128_cfb8 ( ) . iv_len ( )
227+ . expect ( "iv_len should not be None" ) ,
226228 CipherType :: Aes128Cfb | CipherType :: Aes128Cfb128 => {
227229 symm:: Cipher :: aes_128_cfb128 ( ) . iv_len ( )
228230 . expect ( "iv_len should not be None" )
229231 }
230- CipherType :: Aes256Cfb1 => {
231- symm:: Cipher :: aes_256_cfb1 ( ) . iv_len ( )
232- . expect ( "iv_len should not be None" )
233- }
234- CipherType :: Aes256Cfb8 => {
235- symm:: Cipher :: aes_256_cfb8 ( ) . iv_len ( )
236- . expect ( "iv_len should not be None" )
237- }
232+ CipherType :: Aes256Cfb1 => symm:: Cipher :: aes_256_cfb1 ( ) . iv_len ( )
233+ . expect ( "iv_len should not be None" ) ,
234+ CipherType :: Aes256Cfb8 => symm:: Cipher :: aes_256_cfb8 ( ) . iv_len ( )
235+ . expect ( "iv_len should not be None" ) ,
238236 CipherType :: Aes256Cfb | CipherType :: Aes256Cfb128 => {
239237 symm:: Cipher :: aes_256_cfb128 ( ) . iv_len ( )
240238 . expect ( "iv_len should not be None" )
241239 }
242240
243- CipherType :: Rc4 => {
244- symm:: Cipher :: rc4 ( ) . iv_len ( )
245- . expect ( "iv_len should not be None" )
246- }
241+ CipherType :: Rc4 => symm:: Cipher :: rc4 ( ) . iv_len ( ) . expect ( "iv_len should not be None" ) ,
247242 CipherType :: Rc4Md5 => 16 ,
248243
249244 #[ cfg( feature = "sodium" ) ]
@@ -410,29 +405,21 @@ impl Display for CipherType {
410405
411406#[ cfg( test) ]
412407mod test_cipher {
413- use crypto:: { new_stream, CipherType , StreamCipher } ;
414408 use crypto:: CryptoMode ;
409+ use crypto:: { new_stream, CipherType , StreamCipher } ;
415410
416411 #[ test]
417412 fn test_get_cipher ( ) {
418413 let key = CipherType :: Aes128Cfb . bytes_to_key ( b"PassWORD" ) ;
419414 let iv = CipherType :: Aes128Cfb . gen_init_vec ( ) ;
420- let mut encryptor = new_stream ( CipherType :: Aes128Cfb ,
421- & key[ 0 ..] ,
422- & iv[ 0 ..] ,
423- CryptoMode :: Encrypt ) ;
424- let mut decryptor = new_stream ( CipherType :: Aes128Cfb ,
425- & key[ 0 ..] ,
426- & iv[ 0 ..] ,
427- CryptoMode :: Decrypt ) ;
415+ let mut encryptor = new_stream ( CipherType :: Aes128Cfb , & key[ 0 ..] , & iv[ 0 ..] , CryptoMode :: Encrypt ) ;
416+ let mut decryptor = new_stream ( CipherType :: Aes128Cfb , & key[ 0 ..] , & iv[ 0 ..] , CryptoMode :: Decrypt ) ;
428417 let message = "HELLO WORLD" ;
429418
430419 let mut encrypted_msg = Vec :: new ( ) ;
431- encryptor. update ( message. as_bytes ( ) , & mut encrypted_msg)
432- . unwrap ( ) ;
420+ encryptor. update ( message. as_bytes ( ) , & mut encrypted_msg) . unwrap ( ) ;
433421 let mut decrypted_msg = Vec :: new ( ) ;
434- decryptor. update ( & encrypted_msg[ ..] , & mut decrypted_msg)
435- . unwrap ( ) ;
422+ decryptor. update ( & encrypted_msg[ ..] , & mut decrypted_msg) . unwrap ( ) ;
436423
437424 assert ! ( message. as_bytes( ) == & decrypted_msg[ ..] ) ;
438425 }
0 commit comments