Skip to content

Commit e99feab

Browse files
committed
Add a result_str method to std.sha1.sha1.
1 parent ac6e113 commit e99feab

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/lib/sha1.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ state type sha1 = state obj {
1919
// until reset is called
2020
fn result() -> vec[u8];
2121

22+
// Same as above, just a hex-string version.
23+
fn result_str() -> str;
24+
2225
// Reset the sha1 state for reuse. This is called
2326
// automatically during construction
2427
fn reset();
@@ -259,6 +262,15 @@ fn mk_sha1() -> sha1 {
259262
fn result() -> vec[u8] {
260263
ret mk_result(st);
261264
}
265+
266+
fn result_str() -> str {
267+
auto r = mk_result(st);
268+
auto s = "";
269+
for (u8 b in r) {
270+
s += _uint.to_str(b as uint, 16u);
271+
}
272+
ret s;
273+
}
262274
}
263275

264276
auto st = rec(h = _vec.init_elt_mut[u32](0u32, digest_buf_len),

0 commit comments

Comments
 (0)