Skip to content

Commit 1b8a1a9

Browse files
committed
Rename *result* to finalize
Implements the API changes from: RustCrypto/traits#161 The `digest` crate now uses `update` and `finalize` nomenclature ala the Initialize-Update-Finalize (IUF) interface naming scheme.
1 parent 347f13f commit 1b8a1a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+94
-95
lines changed

Cargo.lock

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blake2/examples/blake2b_sum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn process<D: Digest + Default, R: Read>(reader: &mut R, name: &str) {
2828
break;
2929
}
3030
}
31-
print_result(&sh.result(), name);
31+
print_result(&sh.finalize(), name);
3232
}
3333

3434
fn main() {

blake2/examples/blake2s_sum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn process<D: Digest + Default, R: Read>(reader: &mut R, name: &str) {
2828
break;
2929
}
3030
}
31-
print_result(&sh.result(), name);
31+
print_result(&sh.finalize(), name);
3232
}
3333

3434
fn main() {

blake2/src/blake2.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ macro_rules! blake2_impl {
290290
self.n
291291
}
292292

293-
fn variable_result<F: FnOnce(&[u8])>(self, f: F) {
293+
fn finalize_variable<F: FnOnce(&[u8])>(self, f: F) {
294294
let n = self.n;
295295
let res = self.finalize_with_flag(0);
296296
f(&res[..n]);
@@ -343,7 +343,7 @@ macro_rules! blake2_impl {
343343
impl FixedOutput for $fix_state {
344344
type OutputSize = $bytes;
345345

346-
fn fixed_result(self) -> Output {
346+
fn finalize_fixed(self) -> Output {
347347
self.state.finalize_with_flag(0)
348348
}
349349
}
@@ -381,7 +381,7 @@ macro_rules! blake2_impl {
381381
<Self as Reset>::reset(self)
382382
}
383383

384-
fn result(self) -> crypto_mac::Output<Self> {
384+
fn finalize(self) -> crypto_mac::Output<Self> {
385385
crypto_mac::Output::new(self.state.finalize_with_flag(0))
386386
}
387387
}

blake2/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//! hasher.update(b"hello world");
1616
//!
1717
//! // read hash digest and consume hasher
18-
//! let res = hasher.result();
18+
//! let res = hasher.finalize();
1919
//! assert_eq!(res[..], hex!("
2020
//! 021ced8799296ceca557832ab941a50b4a11f83478cf141f51f933f653ab9fbc
2121
//! c05a037cddbed06e309bf334942c4e58cdf1a46e237911ccd7fcf9787cbc7fd0
@@ -24,7 +24,7 @@
2424
//! // same example for `Blake2s`:
2525
//! let mut hasher = Blake2s::new();
2626
//! hasher.update(b"hello world");
27-
//! let res = hasher.result();
27+
//! let res = hasher.finalize();
2828
//! assert_eq!(res[..], hex!("
2929
//! 9aec6806794561107e594b1f6a8a6b0c92a0cba9acf5e5e93cca06f781813b0b
3030
//! ")[..]);
@@ -62,7 +62,7 @@
6262
//!
6363
//! // `result` has type `crypto_mac::Output` which is a thin wrapper around
6464
//! // a byte array and provides a constant time equality check
65-
//! let result = hasher.result();
65+
//! let result = hasher.finalize();
6666
//! // To get underlying array use the `into_bytes` method, but be careful,
6767
//! // since incorrect use of the code value may permit timing attacks which
6868
//! // defeat the security provided by the `crypto_mac::Output`

blake2/tests/persona.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn blake2s_persona() {
88
let persona_bytes = persona.as_bytes();
99
let ctx = Blake2s::with_params(&key_bytes, &[], persona_bytes);
1010
assert_eq!(
11-
ctx.result().as_slice(),
11+
ctx.finalize().as_slice(),
1212
&hex!("25a4ee63b594aed3f88a971e1877ef7099534f9097291f88fb86c79b5e70d022")[..]
1313
);
1414
}
@@ -19,5 +19,5 @@ fn blake2b_persona() {
1919
let persona = "personal";
2020
let persona_bytes = persona.as_bytes();
2121
let ctx = Blake2b::with_params(&key_bytes, &[], persona_bytes);
22-
assert_eq!(ctx.result().as_slice(), &hex!("03de3b295dcfc3b25b05abb09bc95fe3e9ff3073638badc68101d1e42019d0771dd07525a3aae8318e92c5e5d967ba92e4810d0021d7bf3b49da0b4b4a8a4e1f")[..]);
22+
assert_eq!(ctx.finalize().as_slice(), &hex!("03de3b295dcfc3b25b05abb09bc95fe3e9ff3073638badc68101d1e42019d0771dd07525a3aae8318e92c5e5d967ba92e4810d0021d7bf3b49da0b4b4a8a4e1f")[..]);
2323
}

gost94/examples/gost94_cryptopro_sum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn process<D: Digest + Default, R: Read>(reader: &mut R, name: &str) {
2828
break;
2929
}
3030
}
31-
print_result(&sh.result(), name);
31+
print_result(&sh.finalize(), name);
3232
}
3333

3434
fn main() {

gost94/examples/gost94_test_sum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn process<D: Digest + Default, R: Read>(reader: &mut R, name: &str) {
2828
break;
2929
}
3030
}
31-
print_result(&sh.result(), name);
31+
print_result(&sh.finalize(), name);
3232
}
3333

3434
fn main() {

gost94/src/gost94.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl Update for Gost94 {
241241
impl FixedOutput for Gost94 {
242242
type OutputSize = U32;
243243

244-
fn fixed_result(mut self) -> GenericArray<u8, U32> {
244+
fn finalize_fixed(mut self) -> GenericArray<u8, U32> {
245245
{
246246
let self_state = &mut self.state;
247247

gost94/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//!
1515
//! // acquire hash digest in the form of GenericArray,
1616
//! // which in this case is equivalent to [u8; 32]
17-
//! let result = hasher.result();
17+
//! let result = hasher.finalize();
1818
//! assert_eq!(result[..], hex!("
1919
//! 1bb6ce69d2e895a78489c87a0712a2f40258d1fae3a4666c23f8f487bef0e22a
2020
//! "));

gost94/src/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ macro_rules! gost94_impl {
3434
impl FixedOutput for $state {
3535
type OutputSize = U32;
3636

37-
fn fixed_result(self) -> GenericArray<u8, Self::OutputSize> {
38-
self.sh.fixed_result()
37+
fn finalize_fixed(self) -> GenericArray<u8, Self::OutputSize> {
38+
self.sh.finalize_fixed()
3939
}
4040
}
4141

groestl/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
//!
2222
//! // acquire hash digest in the form of GenericArray,
2323
//! // which in this case is equivalent to [u8; 32]
24-
//! let result = hasher.result();
24+
//! let result = hasher.finalize();
2525
//! assert_eq!(result[..], hex!("
2626
//! dc0283ca481efa76b7c19dd5a0b763dff0e867451bd9488a9c59f6c8b8047a86
2727
//! "));

groestl/src/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ macro_rules! impl_groestl {
2727
impl FixedOutput for $state {
2828
type OutputSize = $output;
2929

30-
fn fixed_result(mut self) -> GenericArray<u8, Self::OutputSize> {
30+
fn finalize_fixed(mut self) -> GenericArray<u8, Self::OutputSize> {
3131
let block = self.groestl.finalize();
3232
let n = block.len() - Self::OutputSize::to_usize();
3333
GenericArray::clone_from_slice(&block[n..])
@@ -76,7 +76,7 @@ macro_rules! impl_variable_groestl {
7676
self.groestl.output_size
7777
}
7878

79-
fn variable_result<F: FnOnce(&[u8])>(mut self, f: F) {
79+
fn finalize_variable<F: FnOnce(&[u8])>(mut self, f: F) {
8080
let block = self.groestl.finalize();
8181
let n = block.len() - self.groestl.output_size;
8282
f(&block[n..]);

k12/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl KangarooTwelve {
5959
}
6060

6161
/// Get the result as a `Vec<u8>`
62-
pub fn result_vec(mut self, length: usize) -> Vec<u8> {
62+
pub fn finalize_vec(mut self, length: usize) -> Vec<u8> {
6363
let mut output = vec![0u8; length];
6464
self.read(&mut output);
6565
output

k12/tests/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ fn read_bytes<T: AsRef<[u8]>>(s: T) -> Vec<u8> {
3030
fn empty() {
3131
// Source: reference paper
3232
assert_eq!(
33-
KangarooTwelve::new().chain(b"").result_vec(32),
33+
KangarooTwelve::new().chain(b"").finalize_vec(32),
3434
read_bytes(
3535
"1a c2 d4 50 fc 3b 42 05 d1 9d a7 bf ca
3636
1b 37 51 3c 08 03 57 7a c7 16 7f 06 fe 2c e1 f0 ef 39 e5"
3737
)
3838
);
3939

4040
assert_eq!(
41-
KangarooTwelve::new().chain(b"").result_vec(64),
41+
KangarooTwelve::new().chain(b"").finalize_vec(64),
4242
read_bytes(
4343
"1a c2 d4 50 fc 3b 42 05 d1 9d a7 bf ca
4444
1b 37 51 3c 08 03 57 7a c7 16 7f 06 fe 2c e1 f0 ef 39 e5 42 69 c0 56 b8 c8 2e
@@ -47,7 +47,7 @@ fn empty() {
4747
);
4848

4949
assert_eq!(
50-
KangarooTwelve::new().chain(b"").result_vec(10032)[10000..],
50+
KangarooTwelve::new().chain(b"").finalize_vec(10032)[10000..],
5151
read_bytes(
5252
"e8 dc 56 36 42 f7 22 8c 84
5353
68 4c 89 84 05 d3 a8 34 79 91 58 c0 79 b1 28 80 27 7a 1d 28 e2 ff 6d"
@@ -78,7 +78,7 @@ fn pat_m() {
7878
{
7979
let len = 17usize.pow(i);
8080
let m: Vec<u8> = (0..len).map(|j| (j % 251) as u8).collect();
81-
let result = KangarooTwelve::new().chain(&m).result_vec(32);
81+
let result = KangarooTwelve::new().chain(&m).finalize_vec(32);
8282
assert_eq!(result, read_bytes(expected[i as usize]));
8383
}
8484
}
@@ -101,7 +101,7 @@ fn pat_c() {
101101
let c: Vec<u8> = (0..len).map(|j| (j % 251) as u8).collect();
102102
let result = KangarooTwelve::new_with_customization(c)
103103
.chain(&m)
104-
.result_vec(32);
104+
.finalize_vec(32);
105105
assert_eq!(result, read_bytes(expected[i as usize]));
106106
}
107107
}

md2/examples/md2sum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn process<R: Read>(reader: &mut R, name: &str) {
2020
break;
2121
}
2222
}
23-
println!("{:x}\t{}", &sh.result(), name);
23+
println!("{:x}\t{}", &sh.finalize(), name);
2424
}
2525

2626
fn main() {

md2/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//!
1515
//! // acquire hash digest in the form of GenericArray,
1616
//! // which in this case is equivalent to [u8; 16]
17-
//! let result = hasher.result();
17+
//! let result = hasher.finalize();
1818
//! assert_eq!(result[..], hex!("d9cce882ee690a5c1ce70beff3a78c77"));
1919
//! ```
2020
//!
@@ -110,7 +110,7 @@ impl Update for Md2 {
110110
impl FixedOutput for Md2 {
111111
type OutputSize = U16;
112112

113-
fn fixed_result(mut self) -> GenericArray<u8, Self::OutputSize> {
113+
fn finalize_fixed(mut self) -> GenericArray<u8, Self::OutputSize> {
114114
let buf = self
115115
.buffer
116116
.pad_with::<Pkcs7>()

md4/examples/md4sum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn process<D: Digest + Default, R: Read>(reader: &mut R, name: &str) {
2828
break;
2929
}
3030
}
31-
print_result(&sh.result(), name);
31+
print_result(&sh.finalize(), name);
3232
}
3333

3434
fn main() {

md4/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//!
1515
//! // acquire hash digest in the form of GenericArray,
1616
//! // which in this case is equivalent to [u8; 16]
17-
//! let result = hasher.result();
17+
//! let result = hasher.finalize();
1818
//! assert_eq!(result[..], hex!("aa010fbc1d14c795d86ef98c95479d17"));
1919
//! ```
2020
//!
@@ -140,7 +140,7 @@ impl Default for Md4State {
140140
}
141141

142142
impl Md4 {
143-
fn finalize(&mut self) {
143+
fn finalize_inner(&mut self) {
144144
let state = &mut self.state;
145145
let l = (self.length_bytes << 3) as u64;
146146
self.buffer
@@ -167,8 +167,8 @@ impl Update for Md4 {
167167
impl FixedOutput for Md4 {
168168
type OutputSize = U16;
169169

170-
fn fixed_result(mut self) -> GenericArray<u8, Self::OutputSize> {
171-
self.finalize();
170+
fn finalize_fixed(mut self) -> GenericArray<u8, Self::OutputSize> {
171+
self.finalize_inner();
172172

173173
let mut out = GenericArray::default();
174174
LE::write_u32(&mut out[0..4], self.state.s.0);

md5/examples/md5sum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn process<D: Digest + Default, R: Read>(reader: &mut R, name: &str) {
2828
break;
2929
}
3030
}
31-
print_result(&sh.result(), name);
31+
print_result(&sh.finalize(), name);
3232
}
3333

3434
fn main() {

md5/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//!
1515
//! // acquire hash digest in the form of GenericArray,
1616
//! // which in this case is equivalent to [u8; 16]
17-
//! let result = hasher.result();
17+
//! let result = hasher.finalize();
1818
//! assert_eq!(result[..], hex!("5eb63bbbe01eeed093cb22bb8f5acdc3"));
1919
//! ```
2020
//!
@@ -81,7 +81,7 @@ fn convert(d: &GenericArray<u8, U64>) -> &[u8; 64] {
8181

8282
impl Md5 {
8383
#[inline]
84-
fn finalize(&mut self) {
84+
fn finalize_inner(&mut self) {
8585
let state = &mut self.state;
8686
let l = (self.length_bytes << 3) as u64;
8787
self.buffer
@@ -110,9 +110,9 @@ impl FixedOutput for Md5 {
110110
type OutputSize = U16;
111111

112112
#[inline]
113-
fn fixed_result(mut self) -> GenericArray<u8, Self::OutputSize> {
113+
fn finalize_fixed(mut self) -> GenericArray<u8, Self::OutputSize> {
114114
let mut out = GenericArray::default();
115-
self.finalize();
115+
self.finalize_inner();
116116
LE::write_u32_into(&self.state, &mut out);
117117
out
118118
}

ripemd160/examples/ripemd160sum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn process<D: Digest + Default, R: Read>(reader: &mut R, name: &str) {
2828
break;
2929
}
3030
}
31-
print_result(&sh.result(), name);
31+
print_result(&sh.finalize(), name);
3232
}
3333

3434
fn main() {

ripemd160/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//!
1515
//! // acquire hash digest in the form of GenericArray,
1616
//! // which in this case is equivalent to [u8; 20]
17-
//! let result = hasher.result();
17+
//! let result = hasher.finalize();
1818
//! assert_eq!(result[..], hex!("7f772647d88750add82d8e1a7a3e5c0902a346a3"));
1919
//! ```
2020
//!
@@ -80,7 +80,7 @@ impl Update for Ripemd160 {
8080
impl FixedOutput for Ripemd160 {
8181
type OutputSize = U20;
8282

83-
fn fixed_result(mut self) -> GenericArray<u8, Self::OutputSize> {
83+
fn finalize_fixed(mut self) -> GenericArray<u8, Self::OutputSize> {
8484
{
8585
let h = &mut self.h;
8686
let l = self.len << 3;

ripemd320/examples/ripemd320sum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn process<D: Digest + Default, R: Read>(reader: &mut R, name: &str) {
2828
break;
2929
}
3030
}
31-
print_result(&sh.result(), name);
31+
print_result(&sh.finalize(), name);
3232
}
3333

3434
fn main() {

0 commit comments

Comments
 (0)