File tree 2 files changed +16
-14
lines changed
2 files changed +16
-14
lines changed Original file line number Diff line number Diff line change @@ -352,6 +352,7 @@ mod test {
352
352
353
353
use cryptoutil:: { add_bytes_to_bits, add_bytes_to_bits_tuple} ;
354
354
use digest:: Digest ;
355
+ use hex:: FromHex ;
355
356
356
357
/// Feed 1,000,000 'a's into the digest with varying input sizes and check that the result is
357
358
/// correct.
@@ -372,8 +373,10 @@ mod test {
372
373
}
373
374
374
375
let result_str = digest. result_str ( ) ;
376
+ let result_bytes = digest. result_bytes ( ) ;
375
377
376
- assert ! ( expected == result_str) ;
378
+ assert_eq ! ( expected, result_str. as_slice( ) ) ;
379
+ assert_eq ! ( expected. from_hex( ) . unwrap( ) , result_bytes) ;
377
380
}
378
381
379
382
// A normal addition - no overflow occurs
Original file line number Diff line number Diff line change 10
10
11
11
use std:: vec;
12
12
13
+ use hex:: ToHex ;
14
+
13
15
14
16
/**
15
17
* The Digest trait specifies an interface common to digest functions, such as SHA-1 and the SHA-2
@@ -58,23 +60,20 @@ pub trait Digest {
58
60
59
61
/**
60
62
* Convenience function that retrieves the result of a digest as a
61
- * ~str in hexadecimal format .
63
+ * newly allocated vec of bytes .
62
64
*/
63
- fn result_str ( & mut self ) -> ~str {
65
+ fn result_bytes ( & mut self ) -> ~[ u8 ] {
64
66
let mut buf = vec:: from_elem ( ( self . output_bits ( ) +7 ) /8 , 0u8 ) ;
65
67
self . result ( buf) ;
66
- return to_hex ( buf) ;
68
+ buf
67
69
}
68
- }
69
70
70
- fn to_hex ( rr : & [ u8 ] ) -> ~str {
71
- let mut s = ~"";
72
- for b in rr. iter ( ) {
73
- let hex = ( * b as uint ) . to_str_radix ( 16 u) ;
74
- if hex. len ( ) == 1 {
75
- s. push_char ( '0' ) ;
76
- }
77
- s. push_str ( hex) ;
71
+ /**
72
+ * Convenience function that retrieves the result of a digest as a
73
+ * ~str in hexadecimal format.
74
+ */
75
+ fn result_str ( & mut self ) -> ~str {
76
+ self . result_bytes ( ) . to_hex ( )
78
77
}
79
- return s;
80
78
}
79
+
You can’t perform that action at this time.
0 commit comments