Skip to content

Rename *result* to finalize #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blake2/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 blake2/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 blake2/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 blake2/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 blake2/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")[..]);
}
2 changes: 1 addition & 1 deletion gost94/examples/gost94_cryptopro_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 gost94/examples/gost94_test_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 gost94/src/gost94.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl Update for Gost94 {
impl FixedOutput for Gost94 {
type OutputSize = U32;

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

Expand Down
2 changes: 1 addition & 1 deletion gost94/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//!
//! // acquire hash digest in the form of GenericArray,
//! // which in this case is equivalent to [u8; 32]
//! let result = hasher.result();
//! let result = hasher.finalize();
//! assert_eq!(result[..], hex!("
//! 1bb6ce69d2e895a78489c87a0712a2f40258d1fae3a4666c23f8f487bef0e22a
//! "));
Expand Down
4 changes: 2 additions & 2 deletions gost94/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ macro_rules! gost94_impl {
impl FixedOutput for $state {
type OutputSize = U32;

fn fixed_result(self) -> GenericArray<u8, Self::OutputSize> {
self.sh.fixed_result()
fn finalize_fixed(self) -> GenericArray<u8, Self::OutputSize> {
self.sh.finalize_fixed()
}
}

Expand Down
2 changes: 1 addition & 1 deletion groestl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//!
//! // acquire hash digest in the form of GenericArray,
//! // which in this case is equivalent to [u8; 32]
//! let result = hasher.result();
//! let result = hasher.finalize();
//! assert_eq!(result[..], hex!("
//! dc0283ca481efa76b7c19dd5a0b763dff0e867451bd9488a9c59f6c8b8047a86
//! "));
Expand Down
4 changes: 2 additions & 2 deletions groestl/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ macro_rules! impl_groestl {
impl FixedOutput for $state {
type OutputSize = $output;

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

fn variable_result<F: FnOnce(&[u8])>(mut self, f: F) {
fn finalize_variable<F: FnOnce(&[u8])>(mut self, f: F) {
let block = self.groestl.finalize();
let n = block.len() - self.groestl.output_size;
f(&block[n..]);
Expand Down
2 changes: 1 addition & 1 deletion k12/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl KangarooTwelve {
}

/// Get the result as a `Vec<u8>`
pub fn result_vec(mut self, length: usize) -> Vec<u8> {
pub fn finalize_vec(mut self, length: usize) -> Vec<u8> {
let mut output = vec![0u8; length];
self.read(&mut output);
output
Expand Down
10 changes: 5 additions & 5 deletions k12/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ fn read_bytes<T: AsRef<[u8]>>(s: T) -> Vec<u8> {
fn empty() {
// Source: reference paper
assert_eq!(
KangarooTwelve::new().chain(b"").result_vec(32),
KangarooTwelve::new().chain(b"").finalize_vec(32),
read_bytes(
"1a c2 d4 50 fc 3b 42 05 d1 9d a7 bf ca
1b 37 51 3c 08 03 57 7a c7 16 7f 06 fe 2c e1 f0 ef 39 e5"
)
);

assert_eq!(
KangarooTwelve::new().chain(b"").result_vec(64),
KangarooTwelve::new().chain(b"").finalize_vec(64),
read_bytes(
"1a c2 d4 50 fc 3b 42 05 d1 9d a7 bf ca
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
Expand All @@ -47,7 +47,7 @@ fn empty() {
);

assert_eq!(
KangarooTwelve::new().chain(b"").result_vec(10032)[10000..],
KangarooTwelve::new().chain(b"").finalize_vec(10032)[10000..],
read_bytes(
"e8 dc 56 36 42 f7 22 8c 84
68 4c 89 84 05 d3 a8 34 79 91 58 c0 79 b1 28 80 27 7a 1d 28 e2 ff 6d"
Expand Down Expand Up @@ -78,7 +78,7 @@ fn pat_m() {
{
let len = 17usize.pow(i);
let m: Vec<u8> = (0..len).map(|j| (j % 251) as u8).collect();
let result = KangarooTwelve::new().chain(&m).result_vec(32);
let result = KangarooTwelve::new().chain(&m).finalize_vec(32);
assert_eq!(result, read_bytes(expected[i as usize]));
}
}
Expand All @@ -101,7 +101,7 @@ fn pat_c() {
let c: Vec<u8> = (0..len).map(|j| (j % 251) as u8).collect();
let result = KangarooTwelve::new_with_customization(c)
.chain(&m)
.result_vec(32);
.finalize_vec(32);
assert_eq!(result, read_bytes(expected[i as usize]));
}
}
2 changes: 1 addition & 1 deletion md2/examples/md2sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn process<R: Read>(reader: &mut R, name: &str) {
break;
}
}
println!("{:x}\t{}", &sh.result(), name);
println!("{:x}\t{}", &sh.finalize(), name);
}

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions md2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//!
//! // acquire hash digest in the form of GenericArray,
//! // which in this case is equivalent to [u8; 16]
//! let result = hasher.result();
//! let result = hasher.finalize();
//! assert_eq!(result[..], hex!("d9cce882ee690a5c1ce70beff3a78c77"));
//! ```
//!
Expand Down Expand Up @@ -110,7 +110,7 @@ impl Update for Md2 {
impl FixedOutput for Md2 {
type OutputSize = U16;

fn fixed_result(mut self) -> GenericArray<u8, Self::OutputSize> {
fn finalize_fixed(mut self) -> GenericArray<u8, Self::OutputSize> {
let buf = self
.buffer
.pad_with::<Pkcs7>()
Expand Down
2 changes: 1 addition & 1 deletion md4/examples/md4sum.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
8 changes: 4 additions & 4 deletions md4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//!
//! // acquire hash digest in the form of GenericArray,
//! // which in this case is equivalent to [u8; 16]
//! let result = hasher.result();
//! let result = hasher.finalize();
//! assert_eq!(result[..], hex!("aa010fbc1d14c795d86ef98c95479d17"));
//! ```
//!
Expand Down Expand Up @@ -140,7 +140,7 @@ impl Default for Md4State {
}

impl Md4 {
fn finalize(&mut self) {
fn finalize_inner(&mut self) {
let state = &mut self.state;
let l = (self.length_bytes << 3) as u64;
self.buffer
Expand All @@ -167,8 +167,8 @@ impl Update for Md4 {
impl FixedOutput for Md4 {
type OutputSize = U16;

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

let mut out = GenericArray::default();
LE::write_u32(&mut out[0..4], self.state.s.0);
Expand Down
2 changes: 1 addition & 1 deletion md5/examples/md5sum.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
8 changes: 4 additions & 4 deletions md5/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//!
//! // acquire hash digest in the form of GenericArray,
//! // which in this case is equivalent to [u8; 16]
//! let result = hasher.result();
//! let result = hasher.finalize();
//! assert_eq!(result[..], hex!("5eb63bbbe01eeed093cb22bb8f5acdc3"));
//! ```
//!
Expand Down Expand Up @@ -81,7 +81,7 @@ fn convert(d: &GenericArray<u8, U64>) -> &[u8; 64] {

impl Md5 {
#[inline]
fn finalize(&mut self) {
fn finalize_inner(&mut self) {
let state = &mut self.state;
let l = (self.length_bytes << 3) as u64;
self.buffer
Expand Down Expand Up @@ -110,9 +110,9 @@ impl FixedOutput for Md5 {
type OutputSize = U16;

#[inline]
fn fixed_result(mut self) -> GenericArray<u8, Self::OutputSize> {
fn finalize_fixed(mut self) -> GenericArray<u8, Self::OutputSize> {
let mut out = GenericArray::default();
self.finalize();
self.finalize_inner();
LE::write_u32_into(&self.state, &mut out);
out
}
Expand Down
2 changes: 1 addition & 1 deletion ripemd160/examples/ripemd160sum.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
4 changes: 2 additions & 2 deletions ripemd160/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//!
//! // acquire hash digest in the form of GenericArray,
//! // which in this case is equivalent to [u8; 20]
//! let result = hasher.result();
//! let result = hasher.finalize();
//! assert_eq!(result[..], hex!("7f772647d88750add82d8e1a7a3e5c0902a346a3"));
//! ```
//!
Expand Down Expand Up @@ -80,7 +80,7 @@ impl Update for Ripemd160 {
impl FixedOutput for Ripemd160 {
type OutputSize = U20;

fn fixed_result(mut self) -> GenericArray<u8, Self::OutputSize> {
fn finalize_fixed(mut self) -> GenericArray<u8, Self::OutputSize> {
{
let h = &mut self.h;
let l = self.len << 3;
Expand Down
Loading