diff options
| author | Palmer Cox <p@lmercox.com> | 2013-07-27 15:12:49 -0400 |
|---|---|---|
| committer | Palmer Cox <p@lmercox.com> | 2013-08-02 18:49:00 -0400 |
| commit | 2cbe312343a31127de9d8e28f7b4ce04bc48768c (patch) | |
| tree | a1ed39d9409370c6fbfb5f1bef8a54f231608292 | |
| parent | ee3f75366cc1468a4ce8106976eeb9f42eb9965b (diff) | |
| download | rust-2cbe312343a31127de9d8e28f7b4ce04bc48768c.tar.gz rust-2cbe312343a31127de9d8e28f7b4ce04bc48768c.zip | |
Crypto: Remove DigestUtil and convert to default methods on the Digest trait.
| -rw-r--r-- | src/libextra/crypto/digest.rs | 46 | ||||
| -rw-r--r-- | src/libextra/crypto/sha1.rs | 2 | ||||
| -rw-r--r-- | src/libextra/crypto/sha2.rs | 2 | ||||
| -rw-r--r-- | src/libextra/workcache.rs | 3 |
4 files changed, 23 insertions, 30 deletions
diff --git a/src/libextra/crypto/digest.rs b/src/libextra/crypto/digest.rs index 0efd88fdf50..217573a4135 100644 --- a/src/libextra/crypto/digest.rs +++ b/src/libextra/crypto/digest.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - use std::uint; use std::vec; + /** * The Digest trait specifies an interface common to digest functions, such as SHA-1 and the SHA-2 * family of digest functions. @@ -28,6 +28,10 @@ pub trait Digest { /** * Retrieve the digest result. This method may be called multiple times. + * + * # Arguments + * + * * out - the vector to hold the result. Must be large enough to contain output_bits(). */ fn result(&mut self, out: &mut [u8]); @@ -41,23 +45,7 @@ pub trait Digest { * Get the output size in bits. */ fn output_bits(&self) -> uint; -} - -fn to_hex(rr: &[u8]) -> ~str { - let mut s = ~""; - foreach b in rr.iter() { - let hex = uint::to_str_radix(*b as uint, 16u); - if hex.len() == 1 { - s.push_char('0'); - } - s.push_str(hex); - } - return s; -} -/// Contains utility methods for Digests. -/// FIXME: #7339: Convert to default methods when issues with them are resolved. -pub trait DigestUtil { /** * Convenience functon that feeds a string into a digest * @@ -65,23 +53,29 @@ pub trait DigestUtil { * * * in The string to feed into the digest */ - fn input_str(&mut self, input: &str); + fn input_str(&mut self, input: &str) { + self.input(input.as_bytes()); + } /** * Convenience functon that retrieves the result of a digest as a * ~str in hexadecimal format. */ - fn result_str(&mut self) -> ~str; -} - -impl<D: Digest> DigestUtil for D { - fn input_str(&mut self, input: &str) { - self.input(input.as_bytes()); - } - fn result_str(&mut self) -> ~str { let mut buf = vec::from_elem((self.output_bits()+7)/8, 0u8); self.result(buf); return to_hex(buf); } } + +fn to_hex(rr: &[u8]) -> ~str { + let mut s = ~""; + foreach b in rr.iter() { + let hex = uint::to_str_radix(*b as uint, 16u); + if hex.len() == 1 { + s.push_char('0'); + } + s.push_str(hex); + } + return s; +} diff --git a/src/libextra/crypto/sha1.rs b/src/libextra/crypto/sha1.rs index 7ede1978495..cf9604a3c91 100644 --- a/src/libextra/crypto/sha1.rs +++ b/src/libextra/crypto/sha1.rs @@ -241,7 +241,7 @@ impl Digest for Sha1 { #[cfg(test)] mod tests { - use digest::{Digest, DigestUtil}; + use digest::Digest; use sha1::Sha1; #[deriving(Clone)] diff --git a/src/libextra/crypto/sha2.rs b/src/libextra/crypto/sha2.rs index fc420d7179f..46a135a79e7 100644 --- a/src/libextra/crypto/sha2.rs +++ b/src/libextra/crypto/sha2.rs @@ -756,7 +756,7 @@ static H224: [u32, ..8] = [ #[cfg(test)] mod tests { - use digest::{Digest, DigestUtil}; + use digest::Digest; use sha2::{Sha512, Sha384, Sha512Trunc256, Sha512Trunc224, Sha256, Sha224}; struct Test { diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index 4cfe7727354..d28407a984a 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -10,8 +10,7 @@ #[allow(missing_doc)]; - -use digest::DigestUtil; +use digest::Digest; use json; use sha1::Sha1; use serialize::{Encoder, Encodable, Decoder, Decodable}; |
