Skip to content

Commit

Permalink
Rename *result* to finalize
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tarcieri committed Jun 2, 2020
1 parent 5224768 commit 3432658
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/blake2b_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn process<D: Digest + Default, R: Read>(reader: &mut R, name: &str) {
break;
}
}
print_result(&sh.result(), name);
print_result(&sh.finalize(), name);
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/blake2s_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn process<D: Digest + Default, R: Read>(reader: &mut R, name: &str) {
break;
}
}
print_result(&sh.result(), name);
print_result(&sh.finalize(), name);
}

fn main() {
Expand Down
6 changes: 3 additions & 3 deletions src/blake2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ macro_rules! blake2_impl {
self.n
}

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

fn fixed_result(self) -> Output {
fn finalize_fixed(self) -> Output {
self.state.finalize_with_flag(0)
}
}
Expand Down Expand Up @@ -381,7 +381,7 @@ macro_rules! blake2_impl {
<Self as Reset>::reset(self)
}

fn result(self) -> crypto_mac::Output<Self> {
fn finalize(self) -> crypto_mac::Output<Self> {
crypto_mac::Output::new(self.state.finalize_with_flag(0))
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! hasher.update(b"hello world");
//!
//! // read hash digest and consume hasher
//! let res = hasher.result();
//! let res = hasher.finalize();
//! assert_eq!(res[..], hex!("
//! 021ced8799296ceca557832ab941a50b4a11f83478cf141f51f933f653ab9fbc
//! c05a037cddbed06e309bf334942c4e58cdf1a46e237911ccd7fcf9787cbc7fd0
Expand All @@ -24,7 +24,7 @@
//! // same example for `Blake2s`:
//! let mut hasher = Blake2s::new();
//! hasher.update(b"hello world");
//! let res = hasher.result();
//! let res = hasher.finalize();
//! assert_eq!(res[..], hex!("
//! 9aec6806794561107e594b1f6a8a6b0c92a0cba9acf5e5e93cca06f781813b0b
//! ")[..]);
Expand All @@ -44,7 +44,7 @@
//!
//! let mut hasher = VarBlake2b::new(10).unwrap();
//! hasher.update(b"my_input");
//! hasher.variable_result(|res| {
//! hasher.finalize_variable(|res| {
//! assert_eq!(res, [44, 197, 92, 132, 228, 22, 146, 78, 100, 0])
//! })
//! ```
Expand All @@ -62,7 +62,7 @@
//!
//! // `result` has type `crypto_mac::Output` which is a thin wrapper around
//! // a byte array and provides a constant time equality check
//! let result = hasher.result();
//! let result = hasher.finalize();
//! // To get underlying array use the `into_bytes` method, but be careful,
//! // since incorrect use of the code value may permit timing attacks which
//! // defeat the security provided by the `crypto_mac::Output`
Expand Down
4 changes: 2 additions & 2 deletions tests/persona.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn blake2s_persona() {
let persona_bytes = persona.as_bytes();
let ctx = Blake2s::with_params(&key_bytes, &[], persona_bytes);
assert_eq!(
ctx.result().as_slice(),
ctx.finalize().as_slice(),
&hex!("25a4ee63b594aed3f88a971e1877ef7099534f9097291f88fb86c79b5e70d022")[..]
);
}
Expand All @@ -19,5 +19,5 @@ fn blake2b_persona() {
let persona = "personal";
let persona_bytes = persona.as_bytes();
let ctx = Blake2b::with_params(&key_bytes, &[], persona_bytes);
assert_eq!(ctx.result().as_slice(), &hex!("03de3b295dcfc3b25b05abb09bc95fe3e9ff3073638badc68101d1e42019d0771dd07525a3aae8318e92c5e5d967ba92e4810d0021d7bf3b49da0b4b4a8a4e1f")[..]);
assert_eq!(ctx.finalize().as_slice(), &hex!("03de3b295dcfc3b25b05abb09bc95fe3e9ff3073638badc68101d1e42019d0771dd07525a3aae8318e92c5e5d967ba92e4810d0021d7bf3b49da0b4b4a8a4e1f")[..]);
}

0 comments on commit 3432658

Please sign in to comment.