Skip to content

Commit 2cbe312

Browse files
author
Palmer Cox
committed
Crypto: Remove DigestUtil and convert to default methods on the Digest trait.
1 parent ee3f753 commit 2cbe312

File tree

4 files changed

+23
-30
lines changed

4 files changed

+23
-30
lines changed

src/libextra/crypto/digest.rs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
1211
use std::uint;
1312
use std::vec;
1413

14+
1515
/**
1616
* The Digest trait specifies an interface common to digest functions, such as SHA-1 and the SHA-2
1717
* family of digest functions.
@@ -28,6 +28,10 @@ pub trait Digest {
2828

2929
/**
3030
* Retrieve the digest result. This method may be called multiple times.
31+
*
32+
* # Arguments
33+
*
34+
* * out - the vector to hold the result. Must be large enough to contain output_bits().
3135
*/
3236
fn result(&mut self, out: &mut [u8]);
3337

@@ -41,47 +45,37 @@ pub trait Digest {
4145
* Get the output size in bits.
4246
*/
4347
fn output_bits(&self) -> uint;
44-
}
45-
46-
fn to_hex(rr: &[u8]) -> ~str {
47-
let mut s = ~"";
48-
foreach b in rr.iter() {
49-
let hex = uint::to_str_radix(*b as uint, 16u);
50-
if hex.len() == 1 {
51-
s.push_char('0');
52-
}
53-
s.push_str(hex);
54-
}
55-
return s;
56-
}
5748

58-
/// Contains utility methods for Digests.
59-
/// FIXME: #7339: Convert to default methods when issues with them are resolved.
60-
pub trait DigestUtil {
6149
/**
6250
* Convenience functon that feeds a string into a digest
6351
*
6452
* # Arguments
6553
*
6654
* * in The string to feed into the digest
6755
*/
68-
fn input_str(&mut self, input: &str);
56+
fn input_str(&mut self, input: &str) {
57+
self.input(input.as_bytes());
58+
}
6959

7060
/**
7161
* Convenience functon that retrieves the result of a digest as a
7262
* ~str in hexadecimal format.
7363
*/
74-
fn result_str(&mut self) -> ~str;
75-
}
76-
77-
impl<D: Digest> DigestUtil for D {
78-
fn input_str(&mut self, input: &str) {
79-
self.input(input.as_bytes());
80-
}
81-
8264
fn result_str(&mut self) -> ~str {
8365
let mut buf = vec::from_elem((self.output_bits()+7)/8, 0u8);
8466
self.result(buf);
8567
return to_hex(buf);
8668
}
8769
}
70+
71+
fn to_hex(rr: &[u8]) -> ~str {
72+
let mut s = ~"";
73+
foreach b in rr.iter() {
74+
let hex = uint::to_str_radix(*b as uint, 16u);
75+
if hex.len() == 1 {
76+
s.push_char('0');
77+
}
78+
s.push_str(hex);
79+
}
80+
return s;
81+
}

src/libextra/crypto/sha1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl Digest for Sha1 {
241241
#[cfg(test)]
242242
mod tests {
243243

244-
use digest::{Digest, DigestUtil};
244+
use digest::Digest;
245245
use sha1::Sha1;
246246

247247
#[deriving(Clone)]

src/libextra/crypto/sha2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ static H224: [u32, ..8] = [
756756

757757
#[cfg(test)]
758758
mod tests {
759-
use digest::{Digest, DigestUtil};
759+
use digest::Digest;
760760
use sha2::{Sha512, Sha384, Sha512Trunc256, Sha512Trunc224, Sha256, Sha224};
761761

762762
struct Test {

src/libextra/workcache.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
#[allow(missing_doc)];
1212

13-
14-
use digest::DigestUtil;
13+
use digest::Digest;
1514
use json;
1615
use sha1::Sha1;
1716
use serialize::{Encoder, Encodable, Decoder, Decodable};

0 commit comments

Comments
 (0)