Skip to content

Commit 49ff722

Browse files
tarcierinewpavlov
authored andcommitted
rustfmt (RustCrypto#54)
1 parent 0cab63f commit 49ff722

File tree

11 files changed

+205
-161
lines changed

11 files changed

+205
-161
lines changed

block-cipher-trait/src/dev.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
21
#[macro_export]
32
macro_rules! new_test {
43
($name:ident, $test_name:expr, $cipher:ty) => {
54
#[test]
65
fn $name() {
7-
use block_cipher_trait::BlockCipher;
8-
use block_cipher_trait::generic_array::GenericArray;
9-
use block_cipher_trait::generic_array::typenum::Unsigned;
106
use block_cipher_trait::blobby::Blob3Iterator;
7+
use block_cipher_trait::generic_array::typenum::Unsigned;
8+
use block_cipher_trait::generic_array::GenericArray;
9+
use block_cipher_trait::BlockCipher;
1110

1211
fn run_test(key: &[u8], pt: &[u8], ct: &[u8]) -> bool {
1312
let state = <$cipher as BlockCipher>::new_varkey(key).unwrap();
@@ -45,14 +44,22 @@ macro_rules! new_test {
4544
// check that `encrypt_blocks` and `encrypt_block`
4645
// result in the same ciphertext
4746
state.encrypt_blocks(&mut blocks1);
48-
for b in blocks2.iter_mut() { state.encrypt_block(b); }
49-
if blocks1 != blocks2 { return false; }
47+
for b in blocks2.iter_mut() {
48+
state.encrypt_block(b);
49+
}
50+
if blocks1 != blocks2 {
51+
return false;
52+
}
5053

5154
// check that `encrypt_blocks` and `encrypt_block`
5255
// result in the same plaintext
5356
state.decrypt_blocks(&mut blocks1);
54-
for b in blocks2.iter_mut() { state.decrypt_block(b); }
55-
if blocks1 != blocks2 { return false; }
57+
for b in blocks2.iter_mut() {
58+
state.decrypt_block(b);
59+
}
60+
if blocks1 != blocks2 {
61+
return false;
62+
}
5663

5764
true
5865
}
@@ -64,23 +71,25 @@ macro_rules! new_test {
6471
let plaintext = row[1];
6572
let ciphertext = row[2];
6673
if !run_test(key, plaintext, ciphertext) {
67-
panic!("\n\
68-
Failed test №{}\n\
69-
key:\t{:?}\n\
70-
plaintext:\t{:?}\n\
71-
ciphertext:\t{:?}\n",
74+
panic!(
75+
"\n\
76+
Failed test №{}\n\
77+
key:\t{:?}\n\
78+
plaintext:\t{:?}\n\
79+
ciphertext:\t{:?}\n",
7280
i, key, plaintext, ciphertext,
7381
);
7482
}
7583

7684
// test parallel blocks encryption/decryption
7785
if pb != 1 {
7886
if !run_par_test(key, plaintext) {
79-
panic!("\n\
80-
Failed parallel test №{}\n\
81-
key:\t{:?}\n\
82-
plaintext:\t{:?}\n\
83-
ciphertext:\t{:?}\n",
87+
panic!(
88+
"\n\
89+
Failed parallel test №{}\n\
90+
key:\t{:?}\n\
91+
plaintext:\t{:?}\n\
92+
ciphertext:\t{:?}\n",
8493
i, key, plaintext, ciphertext,
8594
);
8695
}
@@ -90,16 +99,16 @@ macro_rules! new_test {
9099
let key = Default::default();
91100
let _ = <$cipher as BlockCipher>::new(&key).clone();
92101
}
93-
}
102+
};
94103
}
95104

96105
#[macro_export]
97106
macro_rules! bench {
98107
($cipher:path, $key_len:expr) => {
99108
extern crate test;
100109

101-
use test::Bencher;
102110
use block_cipher_trait::BlockCipher;
111+
use test::Bencher;
103112

104113
#[bench]
105114
pub fn encrypt(bh: &mut Bencher) {
@@ -124,5 +133,5 @@ macro_rules! bench {
124133
});
125134
bh.bytes = block.len() as u64;
126135
}
127-
}
136+
};
128137
}

block-cipher-trait/src/lib.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
//! This crate defines a set of simple traits used to define functionality of
22
//! block ciphers.
33
#![no_std]
4-
#![doc(html_logo_url =
5-
"https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")]
6-
pub extern crate generic_array;
4+
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")]
75
#[cfg(feature = "dev")]
86
pub extern crate blobby;
7+
pub extern crate generic_array;
98
#[cfg(feature = "std")]
109
extern crate std;
1110

12-
use generic_array::{GenericArray, ArrayLength};
1311
use generic_array::typenum::Unsigned;
12+
use generic_array::{ArrayLength, GenericArray};
1413

15-
mod errors;
1614
#[cfg(feature = "dev")]
1715
pub mod dev;
16+
mod errors;
1817

1918
pub use errors::InvalidKeyLength;
2019

@@ -57,20 +56,20 @@ pub trait BlockCipher: core::marker::Sized {
5756
///
5857
/// If `ParBlocks` equals to 1 it's equivalent to `encrypt_block`.
5958
#[inline]
60-
fn encrypt_blocks(&self,
61-
blocks: &mut ParBlocks<Self::BlockSize, Self::ParBlocks>)
62-
{
63-
for block in blocks.iter_mut() { self.encrypt_block(block); }
59+
fn encrypt_blocks(&self, blocks: &mut ParBlocks<Self::BlockSize, Self::ParBlocks>) {
60+
for block in blocks.iter_mut() {
61+
self.encrypt_block(block);
62+
}
6463
}
6564

6665
/// Decrypt several blocks in parallel using instruction level parallelism
6766
/// if possible.
6867
///
6968
/// If `ParBlocks` equals to 1 it's equivalent to `decrypt_block`.
7069
#[inline]
71-
fn decrypt_blocks(&self,
72-
blocks: &mut ParBlocks<Self::BlockSize, Self::ParBlocks>)
73-
{
74-
for block in blocks.iter_mut() { self.decrypt_block(block); }
70+
fn decrypt_blocks(&self, blocks: &mut ParBlocks<Self::BlockSize, Self::ParBlocks>) {
71+
for block in blocks.iter_mut() {
72+
self.decrypt_block(block);
73+
}
7574
}
7675
}

crypto-mac/src/dev.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
21
#[macro_export]
32
macro_rules! new_test {
43
($name:ident, $test_name:expr, $mac:ty) => {
54
#[test]
65
fn $name() {
7-
use crypto_mac::Mac;
86
use crypto_mac::blobby::Blob3Iterator;
7+
use crypto_mac::Mac;
98

10-
fn run_test(key: &[u8], input: &[u8], tag: &[u8])
11-
-> Option<&'static str>
12-
{
9+
fn run_test(key: &[u8], input: &[u8], tag: &[u8]) -> Option<&'static str> {
1310
let mut mac = <$mac as Mac>::new_varkey(key).unwrap();
1411
mac.input(input);
1512
let result = mac.result_reset();
@@ -40,17 +37,18 @@ macro_rules! new_test {
4037
let input = row[1];
4138
let tag = row[2];
4239
if let Some(desc) = run_test(key, input, tag) {
43-
panic!("\n\
44-
Failed test №{}: {}\n\
45-
key:\t{:?}\n\
46-
input:\t{:?}\n\
47-
tag:\t{:?}\n",
40+
panic!(
41+
"\n\
42+
Failed test №{}: {}\n\
43+
key:\t{:?}\n\
44+
input:\t{:?}\n\
45+
tag:\t{:?}\n",
4846
i, desc, key, input, tag,
4947
);
5048
}
5149
}
5250
}
53-
}
51+
};
5452
}
5553

5654
#[macro_export]
@@ -73,12 +71,12 @@ macro_rules! bench {
7371
($engine:path) => {
7472
extern crate test;
7573

76-
use test::Bencher;
7774
use crypto_mac::Mac;
75+
use test::Bencher;
7876

79-
bench!(bench1_10, $engine, 10);
80-
bench!(bench2_100, $engine, 100);
81-
bench!(bench3_1000, $engine, 1000);
77+
bench!(bench1_10, $engine, 10);
78+
bench!(bench2_100, $engine, 100);
79+
bench!(bench3_1000, $engine, 1000);
8280
bench!(bench3_10000, $engine, 10000);
83-
}
81+
};
8482
}

crypto-mac/src/errors.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub struct MacError;
1010
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
1111
pub struct InvalidKeyLength;
1212

13-
1413
impl fmt::Display for MacError {
1514
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1615
f.write_str("failed MAC verification")
@@ -35,4 +34,4 @@ impl error::Error for InvalidKeyLength {
3534
fn description(&self) -> &str {
3635
"invalid key length"
3736
}
38-
}
37+
}

crypto-mac/src/lib.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
//! This crate provides trait for Message Authentication Code (MAC) algorithms.
22
#![no_std]
3-
#![doc(html_logo_url =
4-
"https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")]
5-
extern crate subtle;
3+
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")]
64
pub extern crate generic_array;
5+
extern crate subtle;
76

8-
#[cfg(feature = "std")]
9-
extern crate std;
107
#[cfg(feature = "dev")]
118
pub extern crate blobby;
9+
#[cfg(feature = "std")]
10+
extern crate std;
1211

13-
use subtle::{Choice, ConstantTimeEq};
14-
use generic_array::{GenericArray, ArrayLength};
1512
use generic_array::typenum::Unsigned;
13+
use generic_array::{ArrayLength, GenericArray};
14+
use subtle::{Choice, ConstantTimeEq};
1615

17-
mod errors;
1816
#[cfg(feature = "dev")]
1917
pub mod dev;
18+
mod errors;
2019

2120
pub use errors::{InvalidKeyLength, MacError};
2221

@@ -73,10 +72,13 @@ pub trait Mac: Clone {
7372
/// implementation that runs in a fixed time.
7473
#[derive(Clone)]
7574
pub struct MacResult<N: ArrayLength<u8>> {
76-
code: GenericArray<u8, N>
75+
code: GenericArray<u8, N>,
7776
}
7877

79-
impl<N> MacResult<N> where N: ArrayLength<u8> {
78+
impl<N> MacResult<N>
79+
where
80+
N: ArrayLength<u8>,
81+
{
8082
/// Create a new MacResult.
8183
pub fn new(code: GenericArray<u8, N>) -> MacResult<N> {
8284
MacResult { code }
@@ -92,16 +94,22 @@ impl<N> MacResult<N> where N: ArrayLength<u8> {
9294
}
9395
}
9496

95-
impl<N> ConstantTimeEq for MacResult<N> where N: ArrayLength<u8> {
97+
impl<N> ConstantTimeEq for MacResult<N>
98+
where
99+
N: ArrayLength<u8>,
100+
{
96101
fn ct_eq(&self, other: &Self) -> Choice {
97102
self.code.ct_eq(&other.code)
98103
}
99104
}
100105

101-
impl<N> PartialEq for MacResult<N> where N: ArrayLength<u8> {
106+
impl<N> PartialEq for MacResult<N>
107+
where
108+
N: ArrayLength<u8>,
109+
{
102110
fn eq(&self, x: &MacResult<N>) -> bool {
103111
self.ct_eq(x).unwrap_u8() == 1
104112
}
105113
}
106114

107-
impl<N> Eq for MacResult<N> where N: ArrayLength<u8> { }
115+
impl<N> Eq for MacResult<N> where N: ArrayLength<u8> {}

0 commit comments

Comments
 (0)