@@ -251,7 +251,11 @@ pub fn sha1() -> Sha1 {
251
251
let rr = mk_result ( self ) ;
252
252
let mut s = ~"";
253
253
for vec:: each( rr) |b| {
254
- s += uint:: to_str_radix ( * b as uint , 16 u) ;
254
+ let hex = uint:: to_str_radix ( * b as uint , 16 u) ;
255
+ if hex. len ( ) == 1 {
256
+ s += "0" ;
257
+ }
258
+ s += hex;
255
259
}
256
260
return s;
257
261
}
@@ -283,6 +287,7 @@ mod tests {
283
287
struct Test {
284
288
input : ~str ,
285
289
output : ~[ u8 ] ,
290
+ output_str : ~str ,
286
291
}
287
292
288
293
fn a_million_letter_a ( ) -> ~str {
@@ -306,6 +311,7 @@ mod tests {
306
311
0x78u8 , 0x50u8 , 0xC2u8 , 0x6Cu8 ,
307
312
0x9Cu8 , 0xD0u8 , 0xD8u8 , 0x9Du8 ,
308
313
] ,
314
+ output_str : ~"a9993e364706816aba3e25717850c26c9cd0d89d"
309
315
} ,
310
316
Test {
311
317
input :
@@ -318,6 +324,7 @@ mod tests {
318
324
0xF9u8 , 0x51u8 , 0x29u8 , 0xE5u8 ,
319
325
0xE5u8 , 0x46u8 , 0x70u8 , 0xF1u8 ,
320
326
] ,
327
+ output_str : ~"84983e441 c3bd26ebaae4aa1f95129e5e54670f1"
321
328
} ,
322
329
Test {
323
330
input : a_million_letter_a ( ) ,
@@ -328,6 +335,7 @@ mod tests {
328
335
0xDBu8 , 0xADu8 , 0x27u8 , 0x31u8 ,
329
336
0x65u8 , 0x34u8 , 0x01u8 , 0x6Fu8 ,
330
337
] ,
338
+ output_str : ~"34 aa973cd4c4daa4f61eeb2bdbad27316534016f"
331
339
} ,
332
340
] ;
333
341
// Examples from wikipedia
@@ -342,6 +350,7 @@ mod tests {
342
350
0xbbu8 , 0x76u8 , 0xe7u8 , 0x39u8 ,
343
351
0x1bu8 , 0x93u8 , 0xebu8 , 0x12u8 ,
344
352
] ,
353
+ output_str : ~"2 fd4e1c67a2d28fced849ee1bb76e7391b93eb12",
345
354
} ,
346
355
Test {
347
356
input : ~"The quick brown fox jumps over the lazy cog",
@@ -352,6 +361,7 @@ mod tests {
352
361
0x0bu8 , 0xd1u8 , 0x7du8 , 0x9bu8 ,
353
362
0x10u8 , 0x0du8 , 0xb4u8 , 0xb3u8 ,
354
363
] ,
364
+ output_str : ~"de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3",
355
365
} ,
356
366
] ;
357
367
let tests = fips_180_1_tests + wikipedia_tests;
@@ -373,6 +383,11 @@ mod tests {
373
383
sh. input_str ( t. input ) ;
374
384
let out = sh. result ( ) ;
375
385
check_vec_eq ( t. output , out) ;
386
+
387
+ let out_str = sh. result_str ( ) ;
388
+ assert ( out_str. len ( ) == 40 ) ;
389
+ assert ( out_str == t. output_str ) ;
390
+
376
391
sh. reset ( ) ;
377
392
}
378
393
@@ -389,6 +404,11 @@ mod tests {
389
404
}
390
405
let out = sh. result ( ) ;
391
406
check_vec_eq ( t. output , out) ;
407
+
408
+ let out_str = sh. result_str ( ) ;
409
+ assert ( out_str. len ( ) == 40 ) ;
410
+ assert ( out_str == t. output_str ) ;
411
+
392
412
sh. reset ( ) ;
393
413
}
394
414
}
0 commit comments