From e99feabf47351a461518760e6f5f5086e11e7c17 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Sat, 26 Mar 2011 17:36:08 -0700 Subject: [PATCH] Add a result_str method to std.sha1.sha1. --- src/lib/sha1.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib/sha1.rs b/src/lib/sha1.rs index b2294a3c14a..3899dddbc27 100644 --- a/src/lib/sha1.rs +++ b/src/lib/sha1.rs @@ -19,6 +19,9 @@ state type sha1 = state obj { // until reset is called fn result() -> vec[u8]; + // Same as above, just a hex-string version. + fn result_str() -> str; + // Reset the sha1 state for reuse. This is called // automatically during construction fn reset(); @@ -259,6 +262,15 @@ fn mk_sha1() -> sha1 { fn result() -> vec[u8] { ret mk_result(st); } + + fn result_str() -> str { + auto r = mk_result(st); + auto s = ""; + for (u8 b in r) { + s += _uint.to_str(b as uint, 16u); + } + ret s; + } } auto st = rec(h = _vec.init_elt_mut[u32](0u32, digest_buf_len),