diff --git a/crypto-mac/src/lib.rs b/crypto-mac/src/lib.rs index a4c2c5acd..ba61ebcad 100644 --- a/crypto-mac/src/lib.rs +++ b/crypto-mac/src/lib.rs @@ -28,10 +28,10 @@ pub trait Mac: Clone { /// Keys size of the [`Mac`] type KeySize: ArrayLength; - /// Create new MAC instance from key with fixed size. + /// Initialize new MAC instance from key with fixed size. fn new(key: &GenericArray) -> Self; - /// Create new MAC instance from key with variable size. + /// Initialize new MAC instance from key with variable size. /// /// Default implementation will accept only keys with length equal to /// `KeySize`, but some MACs can accept range of key lengths. @@ -43,8 +43,8 @@ pub trait Mac: Clone { } } - /// Process input data. - fn input(&mut self, data: &[u8]); + /// Update MAC state with the given data. + fn update(&mut self, data: &[u8]); /// Reset `Mac` instance. fn reset(&mut self); diff --git a/digest/src/dev.rs b/digest/src/dev.rs index 58e7c5ebb..5c7c9a59e 100644 --- a/digest/src/dev.rs +++ b/digest/src/dev.rs @@ -1,6 +1,6 @@ //! Development-related functionality -use super::{ExtendableOutput, Input, Reset, VariableOutput, XofReader}; +use super::{ExtendableOutput, Reset, Update, VariableOutput, XofReader}; use core::fmt::Debug; /// Define test @@ -41,7 +41,7 @@ mod foo { { let mut hasher = D::new(); // Test that it works when accepting the message all at once - hasher.input(input); + hasher.update(input); let mut hasher2 = hasher.clone(); if hasher.result().as_slice() != output { return Some("whole message"); @@ -49,7 +49,7 @@ mod foo { // Test if reset works correctly hasher2.reset(); - hasher2.input(input); + hasher2.update(input); if hasher2.result().as_slice() != output { return Some("whole message after reset"); } @@ -60,7 +60,7 @@ mod foo { let mut left = len; while left > 0 { let take = (left + 1) / 2; - hasher.input(&input[len - left..take + len - left]); + hasher.update(&input[len - left..take + len - left]); left -= take; } if hasher.result().as_slice() != output { @@ -70,7 +70,7 @@ mod foo { // Test processing byte-by-byte let mut hasher = D::new(); for chunk in input.chunks(1) { - hasher.input(chunk) + hasher.update(chunk) } if hasher.result().as_slice() != output { return Some("message byte-by-byte"); @@ -85,9 +85,9 @@ mod foo { { let mut sh = D::new(); for _ in 0..50_000 { - sh.input(&[b'a'; 10]); + sh.update(&[b'a'; 10]); } - sh.input(&[b'a'; 500_000][..]); + sh.update(&[b'a'; 500_000][..]); let out = sh.result(); assert_eq!(out[..], expected[..]); } @@ -98,12 +98,12 @@ pub use self::foo::{digest_test, one_million_a}; /// XOF test pub fn xof_test(input: &[u8], output: &[u8]) -> Option<&'static str> where - D: Input + ExtendableOutput + Default + Debug + Reset + Clone, + D: Update + ExtendableOutput + Default + Debug + Reset + Clone, { let mut hasher = D::default(); let mut buf = [0u8; 1024]; // Test that it works when accepting the message all at once - hasher.input(input); + hasher.update(input); let mut hasher2 = hasher.clone(); { @@ -117,7 +117,7 @@ where // Test if hasher resets correctly hasher2.reset(); - hasher2.input(input); + hasher2.update(input); { let out = &mut buf[..output.len()]; @@ -134,7 +134,7 @@ where let mut left = len; while left > 0 { let take = (left + 1) / 2; - hasher.input(&input[len - left..take + len - left]); + hasher.update(&input[len - left..take + len - left]); left -= take; } @@ -148,7 +148,7 @@ where // Test reading from reader byte by byte let mut hasher = D::default(); - hasher.input(input); + hasher.update(input); let mut reader = hasher.xof_result(); let out = &mut buf[..output.len()]; @@ -165,13 +165,13 @@ where /// Variable-output digest test pub fn variable_test(input: &[u8], output: &[u8]) -> Option<&'static str> where - D: Input + VariableOutput + Reset + Debug + Clone, + D: Update + VariableOutput + Reset + Debug + Clone, { let mut hasher = D::new(output.len()).unwrap(); let mut buf = [0u8; 128]; let buf = &mut buf[..output.len()]; // Test that it works when accepting the message all at once - hasher.input(input); + hasher.update(input); let mut hasher2 = hasher.clone(); hasher.variable_result(|res| buf.copy_from_slice(res)); if buf != output { @@ -180,7 +180,7 @@ where // Test if reset works correctly hasher2.reset(); - hasher2.input(input); + hasher2.update(input); hasher2.variable_result(|res| buf.copy_from_slice(res)); if buf != output { return Some("whole message after reset"); @@ -192,7 +192,7 @@ where let mut left = len; while left > 0 { let take = (left + 1) / 2; - hasher.input(&input[len - left..take + len - left]); + hasher.update(&input[len - left..take + len - left]); left -= take; } hasher.variable_result(|res| buf.copy_from_slice(res)); @@ -203,7 +203,7 @@ where // Test processing byte-by-byte let mut hasher = D::new(output.len()).unwrap(); for chunk in input.chunks(1) { - hasher.input(chunk) + hasher.update(chunk) } hasher.variable_result(|res| buf.copy_from_slice(res)); if buf != output { diff --git a/digest/src/digest.rs b/digest/src/digest.rs index 4d26a0e61..d0a95cd84 100644 --- a/digest/src/digest.rs +++ b/digest/src/digest.rs @@ -1,4 +1,4 @@ -use super::{FixedOutput, Input, Reset}; +use super::{FixedOutput, Reset, Update}; use generic_array::typenum::Unsigned; use generic_array::{ArrayLength, GenericArray}; @@ -13,10 +13,10 @@ pub trait Digest { /// Create new hasher instance fn new() -> Self; - /// Digest input data. + /// Digest data, updating the internal state. /// /// This method can be called repeatedly for use with streaming messages. - fn input>(&mut self, data: B); + fn update>(&mut self, data: B); /// Digest input data in a chained manner. fn chain>(self, data: B) -> Self @@ -49,22 +49,22 @@ pub trait Digest { fn digest(data: &[u8]) -> GenericArray; } -impl Digest for D { +impl Digest for D { type OutputSize = ::OutputSize; fn new() -> Self { Self::default() } - fn input>(&mut self, data: B) { - Input::input(self, data); + fn update>(&mut self, data: B) { + Update::update(self, data); } fn chain>(self, data: B) -> Self where Self: Sized, { - Input::chain(self, data) + Update::chain(self, data) } fn result(self) -> GenericArray { @@ -87,7 +87,7 @@ impl Digest for D { fn digest(data: &[u8]) -> GenericArray { let mut hasher = Self::default(); - Input::input(&mut hasher, data); + Update::update(&mut hasher, data); hasher.fixed_result() } } diff --git a/digest/src/dyn_digest.rs b/digest/src/dyn_digest.rs index 93dfdd08c..e9b56f6d0 100644 --- a/digest/src/dyn_digest.rs +++ b/digest/src/dyn_digest.rs @@ -1,7 +1,7 @@ #![cfg(feature = "std")] use std::boxed::Box; -use super::{FixedOutput, Input, Reset}; +use super::{FixedOutput, Reset, Update}; use generic_array::typenum::Unsigned; /// The `DynDigest` trait is a modification of `Digest` trait suitable @@ -10,7 +10,7 @@ pub trait DynDigest { /// Digest input data. /// /// This method can be called repeatedly for use with streaming messages. - fn input(&mut self, data: &[u8]); + fn update(&mut self, data: &[u8]); /// Retrieve result and reset hasher instance fn result_reset(&mut self) -> Box<[u8]>; @@ -28,9 +28,9 @@ pub trait DynDigest { fn box_clone(&self) -> Box; } -impl DynDigest for D { - fn input(&mut self, data: &[u8]) { - Input::input(self, data); +impl DynDigest for D { + fn update(&mut self, data: &[u8]) { + Update::update(self, data); } fn result_reset(&mut self) -> Box<[u8]> { diff --git a/digest/src/lib.rs b/digest/src/lib.rs index 7dfb7dd37..2c61883b2 100644 --- a/digest/src/lib.rs +++ b/digest/src/lib.rs @@ -41,20 +41,20 @@ use generic_array::{ArrayLength, GenericArray}; #[cfg(feature = "std")] use std::vec::Vec; -/// Trait for processing input data -pub trait Input { +/// Trait for updating digest state with input data. +pub trait Update { /// Digest input data. /// /// This method can be called repeatedly, e.g. for processing streaming /// messages. - fn input>(&mut self, data: B); + fn update>(&mut self, data: B); /// Digest input data in a chained manner. fn chain>(mut self, data: B) -> Self where Self: Sized, { - self.input(data); + self.update(data); self } }