Skip to content

Commit e939e38

Browse files
authored
Merge pull request #111 from RustCrypto/rename-input-to-update
crypto-mac/digest: rename `input` to `update`
2 parents dffe5b2 + b967c90 commit e939e38

5 files changed

Lines changed: 38 additions & 38 deletions

File tree

crypto-mac/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ pub trait Mac: Clone {
2828
/// Keys size of the [`Mac`]
2929
type KeySize: ArrayLength<u8>;
3030

31-
/// Create new MAC instance from key with fixed size.
31+
/// Initialize new MAC instance from key with fixed size.
3232
fn new(key: &GenericArray<u8, Self::KeySize>) -> Self;
3333

34-
/// Create new MAC instance from key with variable size.
34+
/// Initialize new MAC instance from key with variable size.
3535
///
3636
/// Default implementation will accept only keys with length equal to
3737
/// `KeySize`, but some MACs can accept range of key lengths.
@@ -43,8 +43,8 @@ pub trait Mac: Clone {
4343
}
4444
}
4545

46-
/// Process input data.
47-
fn input(&mut self, data: &[u8]);
46+
/// Update MAC state with the given data.
47+
fn update(&mut self, data: &[u8]);
4848

4949
/// Reset `Mac` instance.
5050
fn reset(&mut self);

digest/src/dev.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Development-related functionality
22
3-
use super::{ExtendableOutput, Input, Reset, VariableOutput, XofReader};
3+
use super::{ExtendableOutput, Reset, Update, VariableOutput, XofReader};
44
use core::fmt::Debug;
55

66
/// Define test
@@ -41,15 +41,15 @@ mod foo {
4141
{
4242
let mut hasher = D::new();
4343
// Test that it works when accepting the message all at once
44-
hasher.input(input);
44+
hasher.update(input);
4545
let mut hasher2 = hasher.clone();
4646
if hasher.result().as_slice() != output {
4747
return Some("whole message");
4848
}
4949

5050
// Test if reset works correctly
5151
hasher2.reset();
52-
hasher2.input(input);
52+
hasher2.update(input);
5353
if hasher2.result().as_slice() != output {
5454
return Some("whole message after reset");
5555
}
@@ -60,7 +60,7 @@ mod foo {
6060
let mut left = len;
6161
while left > 0 {
6262
let take = (left + 1) / 2;
63-
hasher.input(&input[len - left..take + len - left]);
63+
hasher.update(&input[len - left..take + len - left]);
6464
left -= take;
6565
}
6666
if hasher.result().as_slice() != output {
@@ -70,7 +70,7 @@ mod foo {
7070
// Test processing byte-by-byte
7171
let mut hasher = D::new();
7272
for chunk in input.chunks(1) {
73-
hasher.input(chunk)
73+
hasher.update(chunk)
7474
}
7575
if hasher.result().as_slice() != output {
7676
return Some("message byte-by-byte");
@@ -85,9 +85,9 @@ mod foo {
8585
{
8686
let mut sh = D::new();
8787
for _ in 0..50_000 {
88-
sh.input(&[b'a'; 10]);
88+
sh.update(&[b'a'; 10]);
8989
}
90-
sh.input(&[b'a'; 500_000][..]);
90+
sh.update(&[b'a'; 500_000][..]);
9191
let out = sh.result();
9292
assert_eq!(out[..], expected[..]);
9393
}
@@ -98,12 +98,12 @@ pub use self::foo::{digest_test, one_million_a};
9898
/// XOF test
9999
pub fn xof_test<D>(input: &[u8], output: &[u8]) -> Option<&'static str>
100100
where
101-
D: Input + ExtendableOutput + Default + Debug + Reset + Clone,
101+
D: Update + ExtendableOutput + Default + Debug + Reset + Clone,
102102
{
103103
let mut hasher = D::default();
104104
let mut buf = [0u8; 1024];
105105
// Test that it works when accepting the message all at once
106-
hasher.input(input);
106+
hasher.update(input);
107107

108108
let mut hasher2 = hasher.clone();
109109
{
@@ -117,7 +117,7 @@ where
117117

118118
// Test if hasher resets correctly
119119
hasher2.reset();
120-
hasher2.input(input);
120+
hasher2.update(input);
121121

122122
{
123123
let out = &mut buf[..output.len()];
@@ -134,7 +134,7 @@ where
134134
let mut left = len;
135135
while left > 0 {
136136
let take = (left + 1) / 2;
137-
hasher.input(&input[len - left..take + len - left]);
137+
hasher.update(&input[len - left..take + len - left]);
138138
left -= take;
139139
}
140140

@@ -148,7 +148,7 @@ where
148148

149149
// Test reading from reader byte by byte
150150
let mut hasher = D::default();
151-
hasher.input(input);
151+
hasher.update(input);
152152

153153
let mut reader = hasher.xof_result();
154154
let out = &mut buf[..output.len()];
@@ -165,13 +165,13 @@ where
165165
/// Variable-output digest test
166166
pub fn variable_test<D>(input: &[u8], output: &[u8]) -> Option<&'static str>
167167
where
168-
D: Input + VariableOutput + Reset + Debug + Clone,
168+
D: Update + VariableOutput + Reset + Debug + Clone,
169169
{
170170
let mut hasher = D::new(output.len()).unwrap();
171171
let mut buf = [0u8; 128];
172172
let buf = &mut buf[..output.len()];
173173
// Test that it works when accepting the message all at once
174-
hasher.input(input);
174+
hasher.update(input);
175175
let mut hasher2 = hasher.clone();
176176
hasher.variable_result(|res| buf.copy_from_slice(res));
177177
if buf != output {
@@ -180,7 +180,7 @@ where
180180

181181
// Test if reset works correctly
182182
hasher2.reset();
183-
hasher2.input(input);
183+
hasher2.update(input);
184184
hasher2.variable_result(|res| buf.copy_from_slice(res));
185185
if buf != output {
186186
return Some("whole message after reset");
@@ -192,7 +192,7 @@ where
192192
let mut left = len;
193193
while left > 0 {
194194
let take = (left + 1) / 2;
195-
hasher.input(&input[len - left..take + len - left]);
195+
hasher.update(&input[len - left..take + len - left]);
196196
left -= take;
197197
}
198198
hasher.variable_result(|res| buf.copy_from_slice(res));
@@ -203,7 +203,7 @@ where
203203
// Test processing byte-by-byte
204204
let mut hasher = D::new(output.len()).unwrap();
205205
for chunk in input.chunks(1) {
206-
hasher.input(chunk)
206+
hasher.update(chunk)
207207
}
208208
hasher.variable_result(|res| buf.copy_from_slice(res));
209209
if buf != output {

digest/src/digest.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{FixedOutput, Input, Reset};
1+
use super::{FixedOutput, Reset, Update};
22
use generic_array::typenum::Unsigned;
33
use generic_array::{ArrayLength, GenericArray};
44

@@ -13,10 +13,10 @@ pub trait Digest {
1313
/// Create new hasher instance
1414
fn new() -> Self;
1515

16-
/// Digest input data.
16+
/// Digest data, updating the internal state.
1717
///
1818
/// This method can be called repeatedly for use with streaming messages.
19-
fn input<B: AsRef<[u8]>>(&mut self, data: B);
19+
fn update<B: AsRef<[u8]>>(&mut self, data: B);
2020

2121
/// Digest input data in a chained manner.
2222
fn chain<B: AsRef<[u8]>>(self, data: B) -> Self
@@ -49,22 +49,22 @@ pub trait Digest {
4949
fn digest(data: &[u8]) -> GenericArray<u8, Self::OutputSize>;
5050
}
5151

52-
impl<D: Input + FixedOutput + Reset + Clone + Default> Digest for D {
52+
impl<D: Update + FixedOutput + Reset + Clone + Default> Digest for D {
5353
type OutputSize = <Self as FixedOutput>::OutputSize;
5454

5555
fn new() -> Self {
5656
Self::default()
5757
}
5858

59-
fn input<B: AsRef<[u8]>>(&mut self, data: B) {
60-
Input::input(self, data);
59+
fn update<B: AsRef<[u8]>>(&mut self, data: B) {
60+
Update::update(self, data);
6161
}
6262

6363
fn chain<B: AsRef<[u8]>>(self, data: B) -> Self
6464
where
6565
Self: Sized,
6666
{
67-
Input::chain(self, data)
67+
Update::chain(self, data)
6868
}
6969

7070
fn result(self) -> GenericArray<u8, Self::OutputSize> {
@@ -87,7 +87,7 @@ impl<D: Input + FixedOutput + Reset + Clone + Default> Digest for D {
8787

8888
fn digest(data: &[u8]) -> GenericArray<u8, Self::OutputSize> {
8989
let mut hasher = Self::default();
90-
Input::input(&mut hasher, data);
90+
Update::update(&mut hasher, data);
9191
hasher.fixed_result()
9292
}
9393
}

digest/src/dyn_digest.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![cfg(feature = "std")]
22
use std::boxed::Box;
33

4-
use super::{FixedOutput, Input, Reset};
4+
use super::{FixedOutput, Reset, Update};
55
use generic_array::typenum::Unsigned;
66

77
/// The `DynDigest` trait is a modification of `Digest` trait suitable
@@ -10,7 +10,7 @@ pub trait DynDigest {
1010
/// Digest input data.
1111
///
1212
/// This method can be called repeatedly for use with streaming messages.
13-
fn input(&mut self, data: &[u8]);
13+
fn update(&mut self, data: &[u8]);
1414

1515
/// Retrieve result and reset hasher instance
1616
fn result_reset(&mut self) -> Box<[u8]>;
@@ -28,9 +28,9 @@ pub trait DynDigest {
2828
fn box_clone(&self) -> Box<dyn DynDigest>;
2929
}
3030

31-
impl<D: Input + FixedOutput + Reset + Clone + 'static> DynDigest for D {
32-
fn input(&mut self, data: &[u8]) {
33-
Input::input(self, data);
31+
impl<D: Update + FixedOutput + Reset + Clone + 'static> DynDigest for D {
32+
fn update(&mut self, data: &[u8]) {
33+
Update::update(self, data);
3434
}
3535

3636
fn result_reset(&mut self) -> Box<[u8]> {

digest/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ use generic_array::{ArrayLength, GenericArray};
4141
#[cfg(feature = "std")]
4242
use std::vec::Vec;
4343

44-
/// Trait for processing input data
45-
pub trait Input {
44+
/// Trait for updating digest state with input data.
45+
pub trait Update {
4646
/// Digest input data.
4747
///
4848
/// This method can be called repeatedly, e.g. for processing streaming
4949
/// messages.
50-
fn input<B: AsRef<[u8]>>(&mut self, data: B);
50+
fn update<B: AsRef<[u8]>>(&mut self, data: B);
5151

5252
/// Digest input data in a chained manner.
5353
fn chain<B: AsRef<[u8]>>(mut self, data: B) -> Self
5454
where
5555
Self: Sized,
5656
{
57-
self.input(data);
57+
self.update(data);
5858
self
5959
}
6060
}

0 commit comments

Comments
 (0)